Just appeal to the definitions.
First suppose g^-1(O) is open for each open subset O of R. Fix a real number x, and let epsilon be given. The neighborhood N centered at g(x) with radius epsilon is an open set, so the inverse image of N under g is an open set containing x. Thus there is a neighborhood V of x with radius delta such that V is a subset of g^-1(N); you should be able to finish up the forward direction from here.
The reverse implication plays out similarly. If g is continuous at x, then there exists a delta such that whenever y is less than delta apart from x, g(y) is in a neighborhood of g(x) with radius epsilon. You can fill in the details, but this pretty much shows that the inverse image of this epsilon-neighborhood is open. Since the inverse image of any open set is the union of the inverse images of the neighborhoods whose union is that open set, it follows that the inverse image under g of any open set is itself open.