When to store energy in a stochastic environment