The popularity of rooftop solar and home-scale batteries brings a fantastic opportunity to homeowners for using energy more flexibly and achieving benefits from trading electricity. This paper narrates a research work of how home energy management systems (HEMSs) maximize profits from buying electricity at a fixed price from utility and selling the surplus energy to an aggregator. Appropriate optimization problems are formulated with technical constraints of household devices and from connection requirements including a volt-watt function installed in the inverter of the rooftop solar-battery system. HEMS responses are optimized in two stages. The first stage is a stochastic program for planning an optimal energy commitment to an aggregator considering forecast errors and the predicted power curtailment. On the day of operation, each HEMS tries to follow the committed energy plan when determining optimal responses in the real-Time condition. Effectiveness of the proposed method is well illustrated through a simulation of a Japanese low-voltage system. Results show that forecast errors and power limitation due to volt-watt functions should be addressed to improve home benefits.