as you said metals and non-metals react with oxygen to produce their oxides ,which are basic and acidic in nature
for example
magnesium reacts with oxygen to form magnesiumoxide but why then a non-metal like sulphur react with oxygen and form sulphur dioxide why not sulphur oxide??
Sulfur has a valency of 4 i.e. it has 4 valence electrons and therefore it combines with 2 oxygen atoms (oxygen atoms have 2 valence electrons). Thus, compound of sulfur and oxygen will be sulfur dioxide and not sulfur oxide.