In the present study an ab initio investigation on the AlN:Er system for concentrations of Er ranging from 0.78 to 12.5 % is presented. The crystallographic localisation of the rare earth atoms in the wurtzite lattice is determined, elucidating previously published experimental deductions, and the existence of a solid solution in the AlN:Er system in this range is confirmed.Er incorporation in the tetrahedral and octahedral insertion sites is shown to be thermodynamically metastable and is found to induce shallow states in the bandgaps. The effect of Er concentration on the lattice constants and bandgaps and bandstructures of the ErxAl1-xN ternary compound is presented. Finally, in accordance with experimental specifications, Er incorporation in the AlNO system is also examined.