This paper presents an optimal battery management and control algorithm for Photo-Voltaic (PV) stations capacity firming. The proposed method uses a dynamic programming based optimization and control architecture to manage the output of Battery Energy Storage System (BESS) so that PV station output swings are reduced significantly. First, Battery Energy Storage System (BESS) and PV station located in a medium voltage distribution network on a North American Power grid is modeled along with the reduced order feeder model. Then, the proposed algorithm is implemented on the distribution feeder based on the feeder data streamed through utility communication infrastructure to the control station. The theoretical formulation, simulation and implementation results are discussed in detail in this paper.