The problem of residual strain in GaN epilayers is currently the attention of many studies, since it affects the optical and electrical properties of the epilayers. In order to discuss the origin of this residual strain, we have grown a series of GaN epilayers onto AlN buffer layers, sapphire (0001) being used as substrate. The buffer layer is usually deposited in an amorphous state and is recrystallized by a thermal annealing. Here we have made a systematic study of the buffer recrystallization by changing the annealing temperature and the annealing time. The surface morphology is probed using Atomic Force Microscopy (AFM). The lattice parameter c is carried out from accurate x-ray diffraction measurements. The GaN layers were studied by low temperature photoluminescence and reflectivity. The amount of residual strain is calibrated from the position of the A exciton and the optical quality of the layers is assessed from the photoluminescence linewidths. The longer the annealing time the better the strain relaxation in AlN buffer layers and the higher the lattice mismatch with GaN overlayers.