High quality AlN layers with full widths at half maximum values of 10 arcmin and average surface roughness (rms) of 48Å were grown by molecular beam epitaxy on Si(111) substrates. A systematic study and optimization of the growth conditions was performed in order to use these AlN layers as buffers in the growth of GaN films. Atomic force microscopy (AFM) and X-ray diffraction (XRD) techniques were employed to determine the surface and structural quality of the layers. Best AlN films were obtained at high substrate temperatures (Tsubs>900°C) and III/V ratios close to stoichiometry. Growth conditions with III/V ratios beyond stoichiometry (Al-rich) did not further improve the crystal quality. In these cases a higher substrate temperature is needed to prevent condensation of Al on the surface. GaN films with full width at half maximum of 10 arcmin and improved optical properties were grown on top of optimized AlN buffer layers.