Battery management for energy storage