In this paper, we investigate by ab initio DFT how the O:H ratio influences the formation and lattice energy, metastability, and optical properties of Y and La anion-disordered ROxH3-2x oxyhydrides. To achieve this, a set of special quasirandom structures (SQS) is introduced to model anion-disorder along the whole RH3-R2O3 composition line. A comparison with an extensive set of anion-ordered polymorphs of the same composition shows the comparable energy of the anion-disordered phase, which, in particular, in the H-rich composition interval showed the lowest relative energy. In turn, the metastability of the anion-disordered phase depends on the cation size (Y versus La), which determines the maximum H content above which the CaF2-type structure itself becomes unstable. To overcome the accuracy limitations of classical DFT, the modified Becke-Johnson (mBJ) scheme is employed in the study of the electronic properties. We show that major differences occur between H-rich and O-rich R oxyhydrides, as the octahedral H- present for x<1 form electronic states at the top of the valence band, which reduce the energy band gap and dominate the electronic transitions at lower energies, thus increasing the refractive index of the material in the VIS-nIR spectral range. Comparing the DFT results to experimental data on photochromic Y oxyhydride films reinforces the hypothesis of anion-disorder in the H-rich films (x<1), while it hints towards some degree of anion ordering in the O-rich ones (x>1). Our paper exemplifies a strategy to calculate ab initio the electronic/optical properties of a wide range of materials with occupational disorder.