This paper proposes an online optimal tracking al- gorithm to provide the desired voltage magnitude and frequency at the load. This eventually will work as a DC/AC microinverter that with appropriate switching of semiconductor devices will convert low DC voltage to high AC voltage. An L ́ C filter is used to reduce the effects caused by switching semiconductor devices. The proposed control scheme ensures a good tracking of an exosystem that provides the desired voltage magnitude and frequency. It builds upon the ideas of approximate dynamic programming (ADP) and uses only partial information of the system and exosystem. A Lyapunov stability proof ensures that the closed-loop system is asympotically stable. Finally, simulations show the effectiveness of the proposed approach.