Space is not an absolute vacuum. Large amounts of hydrogen and to a lesser extent helium, and a few bits of other stuff were created in the Big Bang. A lot of that matter has condensed into galaxies and stars, and gas clouds. But not all, there are lots of atoms and ions zipping around.
Why oxygen can be found in our solar system is a different question. As I understand it, oxygen is mainly created by fusion processes in stars. Some stars explode in a supernova, and that way the oxygen (and other elements) end up in vast clouds of gas. Those clouds can later form new stars, and planets, and the other objects found in our solar system. So the oxygen does not just appear from 'nothing'.