Battery energy storage based balancing of a microgrid