Free and bound variables in a lambda-calculus term
The free variables in the term you give are $f$ and $g$, $x$ is bound by the $\lambda$-binder.

I am also confused what you mean by "expanding"?  But I guess you want to abstract away those free variables.  If that is true, then you will get $\lambda x . \lambda f . \lambda g . f\ (g\ x)$ (or with the parameters permuted in another way.)