Optimize energy storage systems