When do I use mengapa and when do I use kenapa?
"mengapa" is formal.
"kenapa" is informal.
"mengapa" is the formal style ("baku"), it's the form that should be used in formal writing.
"kenapa" is informal, it's better not to use this in formal writing, but it's absolutely fine to use it in daily speech.
Just some more addition; outside Java, especially in Sumatra, people say mengapa or shortened 'ngapa more often than kenapa--even in informal speech. Kenapa is a loanword from Javanese and used mainly in Java (including the capital Jakarta).