We consider the operation of a wind turbine and a connected local battery or other electrical storage device, taking into account varying wind speed, with the goal of maximizing the total energy generated while respecting limits on the time derivative (gradient) of power delivered to the grid. We use the turbine inertia as an additional energy storage device, by varying its speed over time, and coordinate the flows of energy to achieve the goal. The control variables are turbine pitch, generator torque, and charge/discharge rates for the storage device, each of which can be varied over given ranges. The system dynamics are quite nonlinear, and the constraints and objectives are not convex functions of the control inputs, so the resulting optimal control problem is difficult to solve globally. In this paper, we show that by a novel change of variables, which focuses on power flows, we can transform the problem to one with linear dynamics and convex constraints. Thus, the problem can be globally solved, using robust, fast solvers tailored for embedded control applications. We implement the optimal control problem in a receding horizon manner and provide extensive closed-loop tests with real wind data and modern wind forecasting methods. The simulation results using real wind data demonstrate the ability to reject the disturbances from fast changes in wind speed, ensuring certain power gradients, with an insignificant loss in energy production.