Addressing your first question.
Whites position is preferable for the following reasons:
1. Space advantage.
2. Lead in development.
Sure the rook is hanging, but if black captures it. he has traded off a developed bishop, for an undeveloped rook. This further helps white cause.
Now onto your next question.
"After 8...Be4 the engine recommends the move 9. O-O."
Now your line...
After 8...Be4 the engine recommends the move 9. O-O. But after 9. Nh4 Bxg2 10. Nxg2 Bxd4, white only loses a pawn instead of trading a rook for a bishop. I don't see any immediate advantages for white, so I assume it has something to do with the position of white's pieces versus black's. Or maybe because white has more active pieces?