Are you asking because you are visiting Japan and want to know when to bow, or are you asking out of curiousity for the right answer?
I usually see people bowing for hello and goodbye. Also for apologies. Of course, if someone bows to you, you should bow back.
Most casual bows are short, quick, often only brief head nods.
Since you are a foreigner are exempt from these rules anyways, unless you go to some really backwoods place, or you meet someone who doesn't like foreigners.
This is only a partial answer, I apologize for that.
http://gojapan.about.com/cs/etiquettein ... bowing.htm