The fuel sending unit looks like this and is located inside in the gas tank.
It uses a float that moves down as the gasoline in the tank goes down. It converts the travel of the float into electrical voltage, and is sent to a special metal spring that's attached to the fuel gauge. This metal spring is sensitive to varying voltage, and is how it moves the needle. Fuel sending units become inaccurate because they develop excessive resistance in the circuitry, which to the gauge reads as lower fuel level.
I'm not sure exactly how an O2 sensor works, but I do know it's used to provide feedback to the ECU as to how the emissions of the engine are. On OBD-I vehicles, there is an O2 sensor mounted on the exhaust downpipe. OBD-II vehicles also have a second O2 sensor mounted in the catalytic converter to measure the efficiency of the cat. A common problem that causes the "check engine" light to come on is a faulty O2 sensor, as to whether replacing it will improve gas mileage, it couldn't hurt