x264 is the way to go!! google it , you will find a lot of info about it.
It has the characteristic of producing excellent quality even at 400-500 kbps bitrate along with aac as the audio codec(using nero aac encoder which is free)
I recommend two programs to encode to x264 , both being free -
1)megui - excellent with a lot of options but with a steeper learning curve
2)Staxrip - excellent for beginners
Both programs also allow to encode files with xvid+mp3 audio.
Disadvantages of x264 is that it requires higher processing power to decode and it is incompatible with standalone divx players.
Hope this answers your question..