We present a numerically stable optimized effective potential (OEP) method based on Gaussian basis sets. The key point of the approach is a sequence of preprocessing steps of the auxiliary basis set used to represent exchange or correlation potentials, the Kohn-Sham (KS) response function, and the right-hand side of the OEP equation in conjunction with a representation of exchange or correlation potentials via exchange or correlation charge densities whose electrostatic potentials generate the potentials. Due to the preprocessing, standard Gaussian basis sets from basis set libraries can be used in OEP calculations. As examples, we present numerical stable computational setups based on aux-cc-pwCVXZ basis sets with X = T, Q, 5 for the orbitals and aux-cc-pVDZ/mp2fit and aux-cc-pVTZ/mp2fit auxiliary basis sets and use them to calculate KS exchange potentials with the exact exchange-only KS method for various atoms and molecules. The resulting exchange potentials not only are numerically stable and physically reasonable but also show convergence with increasing quality of the orbital basis sets. The effect of incorporating exact conditions that the KS exchange potential has to obey is discussed. Moreover, it is briefly demonstrated that the presented approach not only works for KS exchange potentials but equally well for correlation potentials within the direct random phase approximation. Besides for OEP methods, the introduced preprocessing of auxiliary basis sets should also be beneficial in procedures to calculate back effective KS potentials from given electron densities.