Optimal Battery Management System of a Wireless Sensor Node