think about it with english: do you speak formally to your friends? or do you speak formally to your elderlies and teachers and stuff. german is not all that different then english... you greet a stranger formally and superiors formally, you would generally greet a friend more casually. so, yes, greet strangers and professionals formally, and friends and peers casually, to answer your question