This paper presents a model of a distributed generation system that could operate both autonomously and connected with the grid. Mathematical models of the distributed energy resources were used to study the dynamic behavior of the interconnected system that includes a three-level control system. State-space models for entire grid-connected system were developed and the small-signal stability of the system was studied. All models were built using MATLAB/Simulink and numerical simulations were used to verify and validate the models as well as the operation of the controlled system.