Adopting a numerical method of solving self-consistently the Schrodinger equation and Poisson equation through taking into account the realistic heterostructure potential, which includes the influences of energy band bending and the finite thickness of barriers, and through considering the built-in electric field induced by spontaneous and piezoelectric polarization, the eigenstates and eigenenergies of electrons in two-dimensional electron gas (2DEG) are obtained for wurtzite AlxGa1-xN/AlN/GaN heterostructures with an inserted AlN layer. Based on the continuous dielectric model and the Loudon's uniaxial crystal model, optical-phonon modes and their ternary mixed crystals effect are discussed using the transfer matrix method. Furthermore, the Lei-Ting balance equation is extended in order to investigate the distribution of 2DEG and its size effect as well as ternary mixed crystals effect on electron mobility, which under the influence of each branch of optical-phonon modes are analyzed at room temperature. The results show that the increases of the thickness of inserted AlN layer and the Al component of AlxGa1-xN in the barrier enhance the built-in electric field in the GaN layer, leading 2DEG to be much closer to the interface of a heterostructure. In addition, it can also be found that the scattering from the interface phonons is stronger than from other optical-phonons, the interface phonons play a dominant role in the total mobility. A higher electron mobility can be obtained by adjusting appropriately the thickness of inserted AlN layer and Al component.