A Framework for Optimal Battery Managementfor Wireless