Energy Optimization in IoT Systems