Effect of free carriers and impurities on the density of states and optical spectra of two-dimensional magnetoexcitons