The paper considers the transition of an economy from non-renewable to renewable energy. We set up a canonical growth model with damages in the household's welfare function and two energy sources – non-renewable and renewable energy. To produce renewable energy a capital stock must be built up. A socially optimal solution is considered that takes into account the negative externality from the non-renewable energy. We also study how the optimal solution can be mimicked in a market economy by policies using subsidies and tax rates. To solve the model numerically, we use Nonlinear Model Predictive Control. We study when a transition to renewable energy takes place and whether it occurs before the non-renewable resource is exhausted. In addition, we analyze the impact of the initial values of the non-renewable resource and of the capital stock on the time of paths of the variables.