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:
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

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

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.