This paper proposes a real-time energy management system (EMS) suitable for rooftop PV installations with battery storage. The EMS is connected to a smart grid where the price signals indirectly control the power output of the PV/battery system in response to the demand variation of the electricity networks. The objective of the EMS is to maximize the revenue over a given time period while meeting the battery stored energy constraint. The optimization problem is solved using the method of Lagrange multipliers. The uniqueness of the proposed EMS remains in the reactive real-time control mechanism that compensates for the PV power forecast error. The proposed EMS requires only forecasting the average PV power output over the total optimization period. This is in contrast to the predictive power scheduling techniques that require accurate instantaneous PV power forecast. The proposed EMS method is verified by benchmarking against the predictive brute-force dynamic programming (DP) approach. The simulation analysis considers days with varying solar irradiance profiles. The simulation analysis shows the proposed EMS operating under practical assumptions, where the battery storage capacity is subject to constraints and the PV power output is not known a priori.