This paper deals with energy storage system (ESS) in active distribution networks. The purpose is to install ESSs on the grid to minimize network losses. The problem is expressed as an optimization programming to minimize annualized cost of losses and annualized investment cost of ESSs at the same time. The constraints of the programming are given as security constraints of the network and ESS operational constraints. The network is also equipped with distributed energy resource (DER) and its uncertainty is modeled and dealt by means of stochastic programming. Different DERs including diesel, wind, and solar resources are modeled and studied. The proposed nonlinear mixed integer stochastic programming is solved by particle swarm optimization (PSO). AC power flow is adopted to consider both active and reactive powers in the model. The ESSs are modeled including both active and reactive powers. The introduced planning finds optimal location, capacity, and power for ESSs. Furthermore, the charging-discharging regime for active power of ESSs and injection-absorption pattern for reactive power of ESSs are determined. The introduced methodology is successfully simulated on a typical distribution network. The simulation results confirm that the planned strategy properly installs ESSs on the grid and minimizes network losses. The results demonstrate that the ESSs decrease network losses about 22%. Finally, considering reactive power for ESSs results in about 24% cost reduction.