Energy management in buildings using photovoltaics