We address the optimal energy storage management and sizing problem in the presence of renewable energy and dynamic pricing associated with electricity from the grid. We formulate the problem as a stochastic dynamic program that aims to minimize the long-run average cost of electricity used and investment in storage, if any, while satisfying all the demand. We model storage with ramp constraints, conversion losses, dissipation losses and an investment cost. We prove the existence of an optimal storage management policy under mild assumptions and show that it has a dual threshold structure. Under this policy, we derive structural results, which indicate that the marginal value from storage decreases with its size and that the optimal storage size can be computed efficiently. We prove a rather surprising result, as we characterize the maximum value of storage under constant prices and i.i.d. net-demand processes: if the storage is a profitable investment, then the ratio of the amortized cost of storage to the constant price is less than 1/4. We further perform sensitivity analysis on the size of optimal storage and its gain via a case study. Finally, with a computational study on real data, we demonstrate significant savings with energy storage.