It's not an iMovie problem.
It's a YouTube problem.
You say that you are exporting as an .mp4 file. You also state that the video looks great while previewing it on your local machine. This rules out any iMovie problem.
The only thing left is either
- YouTube problem
- Connection problem
I am reasonably sure it's a YouTube problem - I don't know much about YouTube. You might have to get some kind of 'Premium' account to upload high-quality stuff.
If you say it uploads fine to YouTube, that rules out a connection issue, unless YouTube does some kind of upload speed test to determine what quality to upload. Highly unlikely in my opinion.