Arduino Uno replace with Atmega8
Atmega8 has a smaller memory but should be a pin-compatible replacement to the Atmega328 for most purposes. Note, however, that the Atmega8 does have a smaller memory, and also a few registers are different, so some might not work, but most common ones should work just fine.

In terms of the Arduino environment, you'll need to do two things:


First burn the corresponding Arduino bootloader (the one named "Arduino NG or older w/ ATmega8" in the Arduino IDE) onto your Atmega8 chip. To burn the bootloader onto the Atmega8 chip, you'll have to either use an AVR/ICSP programmer or use another Arduino board as the ISP.
And when you are uploading sketches, be sure to select the correct board (again, the one named "Arduino NG or older w/ ATmega8") from the menu in the Arduino IDE.


EDIT:
Read these documents to understand how to use a second Arduino as an ISP (In-circuit Serial Programmer) in order to burn the bootloader onto a new chip: First, and Second, and Third