Let $P(x,y)$ denote $g(x+y) + g(x) g(y) =g(xy) + g(x) + g(y) $. The important statements that we'd consider are
$$ \begin{array} { l l l }
P(x,y) & : g(x+y) + g(x) g(y) =g(xy) + g(x) + g(y) & (1) \\
P(x,1) & : g(x+1) + g(x) g(1) = 2 g(x) + g(y) & (2) \\
P(x, y+1) & : g(x+y+1) + g(x) g(y+1) = g(xy+x) + g(x) +g(y+1) & (3)\\
\end{array}
$$
Let $g(1) = A$. With $x=y=1$, we get $g(2) + A^2 = 3A$.
With $x=y=2$, we get $g(4) + g(2)^2 = g(4) + 2g(2) $. Hence either $g(2) = 0$ or $g(2) = 2$.
Case 1: If $g(2) = 0$, then $A^2 - 3A = 0$ so $A=0$ or $A=3$.
Case 1a: (This case is incomplete) If $A=0$:
$(2)$ gives us $g(x+1) = 2g(x)$.
$(3)$ gives us $g(x+y+1) +g(x)g(y+1)= g(xy+y) + g(x)+g(y+1)$.
Applying the above gives $2g(x+y)+g(x)2g(y) = g(xy+x) + g(x) + 2g(y)$, or that $2g(x+y) + 2g(x)g(y) = g(xy+x) + g(x) + 2g(y)$.
$(1)$, combined with the above gives us $g(xy+x) = 2g(xy) + g(x) $.
Substitute $y=1$ in the above identity, we get $g(2x) = 3g(x)$.
(Incomplete here)
Comparing with the first equation, we thus have $g(x) = 0 $.
It is easy to check that $g(x) = 0$ is a solution.
Case 1b: If $A=3$:
$(2)$ gives us $g(x+1) = - g(x) + 3$.
$P(x,2)$ gives us $g(x+2) = g(2x) + g(x)$.
From the previous identity, $g(x+2) = -g(x+1) + 3 = g(x)$. Hence $g(2x) = 0$ for all $x$. However, with $x = \frac{1}{2}$, we have a contradiction. There is no solution in this case.
Case 2: If $g(2) = 2$, then $A^2 - 3A +2 = 0 $ so $A= 1$ or $A=2$.
Case 2a: If $A = 1$:
$P(0,1) $ gives us $g(1) + g(0) = g(0) + g(0) + g(1)$ so $g(0) = 0 $.
$(2)$ gives us $g(x+1) = g(x) + g(1)$.
$(3)$ gives us $g(x+y+1) + g(x) g(y+1) = g(xy+x) + g(x) + g(y+1)$. Using the above, this gives us $ g(x+y) + g(x) g(y) = g(xy+x) + g(x) + g(y) $.
$(1)$ gives us $g(x+y) + g(x) g(y) = g(xy) + g(x) + g(y)$. Hence $g(xy+x) = g(xy) + g(x) $.
Now, for non-zero $a, b$, let $x = b$ and $ y = \frac{b}{a}$. This gives us $g(a+b) = g(a) + g(b) $. It is clear that this equation also holds if $a$ or $b$ equals 0, since $g(0) = 0 $. Thus, we have $g(x+y) = g(x) + g(y) $.
This also yields $g(xy) = g(x) g(y)$. With these 2 equations, the only solution is $g(x) = x$. (slight work here, but this is standard in functional equations).
Case 2b: If $A=2$:
$(2)$ gives us $g(x+1) +2g(x) = g(x) + g(x) + g(1)$, so $g(x) = 2$ for all $x$. This is clearly a solution.
In conclusion, we only have the 3 solutions $g(x) = 0$ or $g(x) = 2$ or $g(x) = x$.
First solution: $g(x)=2$
Second solution: $g(x)=2$ for $x\neq 0$ and $g(0)=0$
Now if $g(0)=0$ there are other possibilities. Choose $x=y=2$ and then either $g(2)=0$ or $g(2)=2$.
If $g(2)=0$, then either $g(1)=0$ or $g(1)=3$. For $g(1)=0$, you get $g(n)=0$ for all $n\in\mathbb{Z}$ and continue like this...
– Arash Sep 02 '13 at 00:11