This paper presents a mathematical modeling approach by which to solve the power flow and state estimation problems in electric power systems through a mathematical programming language (AMPL). The main purpose of this work is to show the advantages of representing these problems through mathematical optimization models in AMPL, which is a modeling language extensively used in a wide range of research applications. The proposed mathematical optimization models allow for dealing with particular issues in that they are not usually considered in the classical approach for power flow and state estimation, such as solving the power flow problem considering reactive power limits in generation buses, as well as the treatment of errors in state estimation analysis. Furthermore, the linearized mathematical optimization models for both problems at hand are also presented and discussed. Several tests were carried out to validate the proposed optimization models, evidencing the applicability of the proposed approach.