Future 5G cellular networks, equipped with energy harvesting devices, are uniquely positioned to interoperate with smart grid, due to their resemblance in scale and ubiquity. New interoperable functionalities, such as real-time energy trading and future planning, are of particular interest to improve productivity, but extremely challenging due to the physical characteristics of wireless channels and renewable energy sources, as well as time-varying energy prices. Particularly, a priori knowledge on future wireless channels, energy harvesting, and pricing is unavailable in practice. In this scenario, simple but efficient Lyapunov control theory can be applied to stochastically optimize energy trading and planning. Simulations demonstrate that Lyapunov control can approach the offline optimum which is obtained under the ideal assumption of full a priori knowledge, leading to 65 percent reduction of the operational expenditure of 5G on energy over existing alternatives.