Energy-Efficient Framework for IoT with Enhanced Lifetime and Dynamic Security Solutions