How serious is the oxygen sensor to the maintainance of the vehicle on 2006 Hyundai Santa Fe

Concerned that check engine light comes on every so often, was told it could be the oxygen sensor, or not consistently using premium gas, or the gas cap not closed tightly.

Asked by for the 2006 Hyundai Santa Fe
It is necessary.