Rare-earth (RE) oxyhydride thin films show a color-neutral, reversible photochromic effect at ambient conditions. The origin of the photochromism is the topic of current investigations. Here, we investigated the lattice defects, electronic structure, and crystal structure of photochromic ${\mathrm{YH}}_{x}{\mathrm{O}}_{y}$ and $\mathrm{Gd}{\mathrm{H}}_{x}{\mathrm{O}}_{y}$ thin films deposited by magnetron sputtering using positron annihilation techniques and x-ray diffraction, in comparison with Y, ${\mathrm{YH}}_{\ensuremath{\sim}1.9}$, ${\mathrm{Y}}_{2}{\mathrm{O}}_{3}$, Gd, $\mathrm{Gd}{\mathrm{H}}_{\ensuremath{\sim}1.8}$, and ${\mathrm{Gd}}_{2}{\mathrm{O}}_{3}$ films. Positron annihilation lifetime spectroscopy (PALS) reveals the presence of cation monovacancies in the as-deposited Y and ${\mathrm{YH}}_{\ensuremath{\sim}1.9}$ films at concentrations of $\ensuremath{\sim}{10}^{\ensuremath{-}5}$ per cation. In addition, vacancy clusters and nanopores are found in the as-prepared ${\mathrm{YH}}_{x}{\mathrm{O}}_{y}$ and ${\mathrm{Y}}_{2}{\mathrm{O}}_{3}$ films. Doppler broadening positron annihilation spectroscopy (DB-PAS) of the Y- and Gd-based films reflects the transition from a metallic to an insulating nature of the RE metal, metal hydride, semiconducting oxyhydride and insulating oxide films. In-situ illumination DB-PAS shows the irreversible formation predominantly of di-vacancies, as PALS showed that cation mono-vacancies are already abundantly present in the as-prepared films. The formation of di-vacancies supports conjectures that ${\mathrm{H}}^{\text{--}}$ (and/or ${\mathrm{O}}^{2\text{--}}$) ions become mobile upon illumination, as these will leave anion vacancies behind, some of which may subsequently cluster with cation vacancies present. In addition, in RE oxyhydride films, partially reversible shifts in the Doppler parameters are observed that correlate with the photochromic effect and point to the formation of metallic domains in the semiconducting films. Two processes are discussed that may explain the formation of these metallic domains and the changes in optical properties associated with the photochromic effect. The first process considers the reversible formation of metallic nanodomains with reduced O : H composition by transport of light-induced mobile hydrogen and local oxygen displacements. The second process considers metallic nanodomains resulting from the trapping of photoexcited electrons in an ${e}_{g}$ orbital at the yttrium ions surrounding positively charged hydrogen vacancies that are formed by light-induced removal of hydrogen atoms from octahedral sites. When a sufficiently large concentration, on the order of \ensuremath{\sim}10%, is reached in a certain domain of the film, band formation of the ${e}_{g}$ electrons may occur, leading to an Anderson-Mott insulator-metal transition like the case of yttrium trihydride in these domains.