Battery systems bring technical and economic advantages to electrical distribution systems (EDSs), as they conveniently store the surplus of cheap renewable generation for use at a more convenient time and contribute to peak shaving. Due to the high cost of batteries, technical and economic studies are needed to evaluate their correct allocation within the EDS. To contribute to this analysis, this paper proposes a stochastic mathematical model for the optimal battery allocation (OBA), which can be guided by the optimization of two different economic metrics: net present value (NPV) and internal rate of return (IRR). The effects of the OBA in the EDS are evaluated considering the stochastic variation of photovoltaic generation and load. Tests with the 33-node IEEE test system indicate that OBA results in voltage profile improvement (~1% at peak time), peak reduction (31.17%), increased photovoltaic hosting capacity (18.8%), and cost reduction (3.06%). Furthermore, it was found that the IRR metric leads to a different solution compared to the traditional NPV optimization due to its inherent consideration of the relation between cash flow and investment. Thus, both NPV and IRR-based allocation alternatives can be used by the decision maker to improve economic and technical operation of the EDS.