We study the optimal control of storage which is used for both arbitrage and buffering against unexpected events (shocks), with particular applications to the control of energy systems in a stochastic and typically time-heterogeneous environment. Our philosophy is that of viewing the problem as being formally one of stochastic dynamic programming (SDP), but of recasting the SDP recursion in terms of functions which, if known, would reduce the associated optimisation problem to one which is deterministic, except that it must be re-solved at times when shocks occur. In the case of a perfectly efficient store facing linear buying and selling costs the functions required for this approach may be determined exactly; otherwise they may typically be estimated to good approximation. We provide characterisations of optimal control policies. We consider also the associated deterministic optimisation problem, outlining an approach to its solution which is both computationally tractable and—through the identification of a running forecast horizon—suitable for the management of systems over indefinitely extended periods of time. We give examples based on Great Britain electricity price data.