The formation energies of oxygen and silicon impurities have been examined explicitly in Al0.65Ga0.35N using hybrid exchange-correlation density-functional theory simulations. Both impurities were initialized in on-site substitutional and off-site DX configurations in a range of charge states. The O-N(+1) donor was found to always relax into an on-site configuration, and its formation energy is relatively independent of local chemistry (the configuration of Al and Ga atoms surrounding the defect). By contrast, the O-N(-1) acceptor almost always relaxes into a DX configuration, with a formation energy that is strongly dependent on local chemistry. The differences in formation energy of distinct O-N(-1) defect configurations are understood through the interplay of two qualitative trends in the types of nearest-neighbor bonds (O-Al or O-Ga), as well as the subtler influence of the lengths of the O-Al bonds. Knowledge of O-N(-1) formation energies as well as the relative frequencies of sites with different local chemistry allows one to compute the relative site occupancies of O-N(-1). Because the thermodynamic transition levels associated with different defect configurations are unique, the O-N DX transition is associated with multiple defect levels. Si-III, where III represents the group III cation of Al or Ga, provides an interesting counterexample. Si-III(+1) is predicted to be the dominant charge state across the entire band gap of Al0.65Ga0.35N, and little dependence of the formation energy on the composition of nearby cation sites was found. This is explained by the fact that the first-nearest neighbors are all of the same species (N), so the local environment is similar to a bulk III nitride, in which on-site Si-III(+1) is stable across the same Fermi level range (i.e., below the band gap of Al0.65Ga0.35N). Thus, the trends in the energetics of O-N and( )Si(III) in Al0.65Ga0.35N are both determined by the chemistry of the four nearest-neighbor sites surrounding the defect site.