This paper proposes a novel algorithm to identify degradation in batteries used for power system applications. Unlike conventional battery control methods that try to extend battery lifetime by applying heuristic rules, this approach allows us to maximize battery lifetime within an optimal control framework. We use an online Least Squares (LS) identification method to develop a two-dimensional degradation map that describes the lost battery charge as a function of the battery state of charge and the applied current. We project the degradation map to an economic cost function that associates each discrete control action with its utilization cost. Additionally, we develop a nonlinear battery model to capture fast battery dynamics including the rate capacity effect and we identify its parameters with a nonlinear LS method. We demonstrate the usefulness of the approach by presenting a model predictive control (MPC) scheme for a peak shave application in which we use a linearized version of the battery model along with the degradation cost function. We use a high-fidelity lithium ion electrochemical battery model to simulate a real battery system and we show that the MPC scheme increases the battery lifetime by a factor of 2.6 and the internal rate of return by 11 percentage points as compared to conventional control approaches.