Mathematical Tools for Optimization of Energy Consumption in Wireless Sensor Networks