Energy storage will be key to overcoming the intermittency and variability of renewable energy sources. Here, we propose a metric for the cost of energy storage and for identifying optimally sized storage systems. The levelized cost of energy storage is the minimum price per kWh that a potential investor requires in order to break even over the entire lifetime of the storage facility. We forecast the dynamics of this cost metric in the context of lithium-ion batteries and demonstrate its usefulness in identifying an optimally sized battery charged by an incumbent solar PV system. Applying the model to residential solar customers in Germany, we find that behind-the-meter storage is economically viable because of the large difference between retail rates and current feed-in tariffs. In contrast, investment incentives for battery systems in California derive principally from a state-level subsidy program.