Optimal Policies for Wireless Networks With Energy Harvesting