Atmega8 vs Atmega328

Does Atmega8 work with Arduino Uno? Do they have the exact same pinout as the Atmega328 so that when I plug it into the socket everything will work just fine?

Yes. Different bootloader needed for downloading code.
See the Arduino NG boards here:
https://www.arduino.cc/en/Main/Boards
The IDE still has "Arduino NG or older w/ ATmega8"

as a board type even (thru 1.6.5 anyway).

boards.txt entry for it:

## Arduino NG or older w/ ATmega8

 ## ------------------------------

 atmegang.menu.cpu.atmega8=ATmega8

 atmegang.menu.cpu.atmega8.upload.maximum_size=7168

 atmegang.menu.cpu.atmega8.upload.maximum_data_size=1024

 atmegang.menu.cpu.atmega8.bootloader.low_fuses=0xdf

 atmegang.menu.cpu.atmega8.bootloader.high_fuses=0xca

 atmegang.menu.cpu.atmega8.bootloader.file=atmega8/ATmegaBOOT-prod-firmware-2009-11-07.hex

atmegang.menu.cpu.atmega8.build.mcu=atmega8

Is Optiboot or Adaboot compatible? can I even flash them into the atmega8?

I don't know about 'compatible', for sure you can load them on, whether they work is a different question.

Due to a bug in Arduino AVR Boards you can't Burn Bootloader to ATmega8 using the "Arduino NG or older" board selection(Write bootloader - problem on ATmega8 · Issue #2075 · arduino/Arduino · GitHub).

I recommend using

Which supports ATmega8 and doesn't have that bug and has the optiboot bootloader for it too.