Renewable Energy Sources (RESs) are gaining traction in active distribution systems due to their cost-effectiveness and the imperative for energy transition. However, their integration poses technical hurdles, including reverse power flow (RPF) and power balance issues, potentially resulting in energy curtailment. Energy Storage Systems (ESSs) have emerged as a pivotal technology to mitigate these challenges by storing energy from RESs and harmonizing their output power with technical constraints. This paper introduces a two-stage techno-economic stochastic model for optimizing ESS sizing, allowing for the maximization of installed RESs capacity while considering their stochastic behavior. Investors can leverage this model to enhance profits by factoring in the economic aspects of ESSs and the potential for renewable energy installation, leading to an increase in revenue.