**** _gokigen'yō_
* (honorific prefix)
* ("mood; tide")
* (old-fashioned form for , a conjugation† of )
Altogether means "your mood (being) well", or practically "in good mood; in good shape".
> _Why is it both a greeting and a farewell? I don't think there are other phrases like that but maybe I'm wrong about that._
Well... this word is pretty much analogous in many ways to "Good day!" in English. With the verb omitted, the phrase can stand for both "it is a good day" and "have a good day", thus has dual use as hello and goodbye.
* * *
† The inflection of adjectives is normally called _declension_ , but in Japanese context I'm more comfortable to call it _conjugation_ nevertheless.