This paper presents the development and implementation of a new recurrent neural network for optimization as applied to optimal operation of an electrical microgrid, which is interconnected to the utility grid; moreover, it incorporates batteries, for energy storing and supplying, and an electric car. The proposed neural network determines the optimal amount of power over a time horizon of one week for wind, solar, and battery systems, including that of the electric car, in order to minimize the power acquired from the utility grid and to maximize the power supplied by the renewable energy sources. Simulation results illustrate that generation levels for each energy source over a time horizon can be reached in an optimal form.