Intelligent energy management and demand-response control for a photovoltaic-battery system