Polite greeting used when meeting someone after a while, or in letters/emails. Often answered with はい、元気です or similar.
お久しぶりです。お元気ですか。
Long time no see. How are you?
お元気ですか。最近どうしていますか。
How are you? What have you been up to lately?
お元気ですか is the everyday polite way to ask how someone is, while ご機嫌いかがですか is a more formal, business-or-ceremonial version of the same question.
Polite prefix お + 元気 (health, energy) + です (copula) + question marker か. A standard set phrase.