Foundations of energy storage