We compute an optimal day-ahead dispatch plan for distribution networks with stochastic resources and batteries, while accounting for grid and battery losses. We formulate and solve a scenario-based AC Optimal Power Flow (OPF), which is by construction non-convex. We explain why the existing relaxation methods do not apply and we propose a novel iterative scheme, Corrected DistFlow (CoDistFlow), to solve the scenario-based AC OPF problem in radial networks. It uses a modified branch flow model for radial networks with angle relaxation that accounts for line shunt capacitances. At each step, it solves a convex problem based on a modified DistFlow OPF with correction terms for line losses and node voltages. Then, it updates the correction terms using the results of a full load flow. We prove that under a mild condition, a fixed point of CoDistFlow provides an exact solution to the full AC power flow equations. We propose treating battery losses similarly to grid losses by using a single-port electrical equivalent instead of battery efficiencies. We evaluate the performance of the proposed scheme in a simple and real electrical networks. We conclude that grid and battery losses affect the feasibility of the day-ahead dispatch plan and show how CoDistFlow can handle them correctly.