The integration of renewable energy sources into modern electrical grids contributes to satisfying the continuously increasing energy demand. This can be done in a sustainable way since renewable sources are both inexhaustible and non-polluting. Different renewable energy devices, such as wind power, hydro power, and photovoltaic generators are available nowadays. The main issue with the integration of such devices is their irregular generation capacity (in particular for wind and solar energy). Therefore energy storage units are used to mitigate the fluctuations during generation and supply. In this paper we formulate a model for the Alternate Current Optimal Power Flow (ACOPF) problem consisting of simple dynamics for energy storage systems cast as a finite-horizon optimal control problem. The effect of energy storage is examined by solving a Norwegian demo network. The simulation results illustrate that the addition of energy storage, along with demand based cost functions, significantly reduces the generation costs and flattens the generation profiles.