In the electricity market, customers have many choices to reduce electricity cost if they can economically schedule their power consumption. Renewable hybrid system, which can explore solar or wind sources at low cost, is a popular choice for this purpose nowadays. In this paper optimal energy management for a grid-connected photovoltaic-battery hybrid system is proposed to sufficiently explore solar energy and to benefit customers at demand side. The management of power flow aims to minimize electricity cost subject to a number of constraints, such as power balance, solar output and battery capacity. With respect to demand side management, an optimal control method (open loop) is developed to schedule the power flow of hybrid system over 24h, and model predictive control is used as a closed-loop method to dispatch the power flow in real-time when uncertain disturbances occur. In these two kinds of applications, optimal energy management solutions can be obtained with great cost savings and robust control performance.