Battery Energy Storage Systems (BESS) can mitigate effects of intermittent energy production from renewable energy sources and play a critical role in peak shaving and demand charge management. To optimally size the BESS from an economic perspective, the tradeoff between BESS investment costs, lifetime, and revenue from utility bill savings along with microgrid ancillary services must be taken into account. The optimal size of a BESS is solved via a stochastic optimization problem considering wholesale market pricing. A stochastic model is used to schedule arbitrage services for energy storage based on the forecasted energy market pricing while accounting for BESS cost trends, the variability of renewable energy resources, and demand prediction. The uniqueness of the approach proposed in this paper lies in the convex optimization programming framework that computes a globally optimal solution to the financial trade-off solution. The approach is illustrated by application to various realistic case studies based on pricing and demand data from the California Independent System Operator (CAISO). The case study results give insight in optimal BESS sizing from a cost perspective, based on both yearly scheduling and daily BESS operation.