Energy management of photovoltaic-battery system connected with the grid