Energy storage will be key to overcoming the intermittency and variability of renewable energy sources, like wind and solar power. This paper proposes a cost metric for measuring the cost of energy storage and for identifying optimally sized energy storage systems. The levelized cost of energy storage (LCOES) metric is calibrated as the minimum price per kWh stored that an investor would require in order to break even over the entire lifetime of the storage facility. We forecast the dynamics of this levelized cost metric in the context of lithium-ion batteries and demonstrate its usefulness in identifying the optimal size of a battery that is charged by an incumbent solar PV system. Applying the model to residential solar customers in Germany and California, we find that behind-the-meter storage is economically viable in Germany because of the large difference between retail rates and current feed-in-tariffs. In contrast, investment incentives for behind-the-meter battery systems in California derive principally from a state-level subsidy program. An optimally sized battery will allow the German household to cover its entire load for representative days during three months of the year, while this will be the case for only one month in California.