The easy part is to show that $f$ and $g$ have the same Fourier coefficients. The hard part is to show that $f$ and $g$ are identically equal.
First show that $f$ and $g$ have the same Fourier series.
From periodicity of the series, we can consider any interval $[\alpha, \alpha+ 2\pi]$, and adopting standard notation replace $a_0$ with $a_0/2$.
We have
$$\tag{1}g(x) = a_0/2 + \sum_{n=1}^\infty (a_n \cos nx + b_n \sin nx)$$
where the series is uniformly convergent on the interval, and, since each term in the series is continuous, it follows from uniform convergence that $g$ is continuous.
Multiplying by $\sin mx$ and integrating we get
$$\tag{2}\frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}g(x) \sin mx \,dx \\= \frac{a_0}{2\pi}\int_{\alpha}^{\alpha + 2\pi}\sin mx \, dx +\frac{1}{\pi}\int_{\alpha}^{\alpha + 2\pi}\sum_{n=1}^\infty(a_n \cos nx \sin mx + b_n \sin nx \sin mx) \, dx.$$
Since (1) is uniformly convergent and $\sin mx$ is bounded, the series on the RHS of (2) is uniformly convergent and can be integrated term by term to obtain
$$\tag{3}\frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}g(x) \sin mx \,dx \\= \frac{a_0}{2\pi}\int_{\alpha}^{\alpha + 2\pi}\sin mx \, dx +\sum_{n=1}^\infty\frac{a_n}{\pi}\left(\int_{\alpha}^{\alpha + 2\pi}\cos nx \sin mx \, dx \right) + \frac{b_n}{\pi} \left(\int_{\alpha}^{\alpha + 2\pi} \sin nx \sin mx \, dx \right)$$
All the integrals on the RHS of (3) vanish except the integral of $\sin nx \sin mx$ when $n = m$.
Hence,
$$\frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}g(x) \sin mx \,dx = b_m = \frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}f(x) \sin mx \,dx $$.
Similarly we can show
$$\frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}g(x)\,dx = a_0 = \frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}f(x)\,dx , \\ \frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}g(x) \cos mx \,dx = a_m = \frac{1}{\pi} \int_{\alpha}^{\alpha + 2\pi}f(x) \cos mx \,dx. $$
Thus $f$ and $g$ have the same Fourier series.
It still remains to prove that $f = g$.
This follows by showing that if two continuous functions differ at just one point, $f(c) \neq g(c)$, then they cannot have the same Fourier series.
Take $h = f -g$. If $f$ and $g$ have identical Fourier series, then all Fourier coefficients of $h$ vanish, and for any trigonometric polynomial $T_m(x) = A_0/2 + \sum_{n=1}^{m} (A_n \cos nx + B_n \sin nx)$ we have for any $\alpha \in \mathbb{R}$,
$$\tag{4}\int_{\alpha}^{\alpha + 2\pi} h(x) T_m(x) \, dx = 0.$$
We also have $h(c) = f(c) - g(c) \neq 0$ and WLOG can assume that $h(c) > 0$. Since $h$ is continuous , there exists $K > 0$ and $\delta > 0$ such that $h(x) \geqslant K > 0$ when $x \in [c - \delta,c + \delta]$.
It can be shown that $T_m(x) = [1 + \cos(x-c) - \cos \delta]^m$ is a trigonometric polynomial satisfying
$$T_m(x) \geqslant 1 \text{ for } x \in [c-\delta,c+\delta] \\ \lim_{m \to \infty} T_m(x) = \infty \text{ uniformly on } [c - \delta/2, c+\delta/2] \\ |T_m(x)| \leqslant 1 \text{ for } x \in [c + \delta , c - \delta + 2\pi]
$$
From these properties it follows that
$$\tag{5} \int_{c - \delta}^{c + \delta} h(x) T_m(x) \, dx \geqslant \int_{c - \delta/2}^{c + \delta/2} h(x) T_m(x) \, dx \geqslant \delta \, K \, \inf T_m(x) $$
and $\int_{c + \delta}^{c - \delta + 2\pi} h(x) T_m(x) \, dx$ is bounded.
Since the RHS of (5) tends to $\infty$ as $m \to \infty$ it follows for sufficiently large $m$
$$\int_{c - \delta}^{c - \delta + 2\pi} h(x) T_m(x) \, dx \neq 0,$$
contradicting (4) and leading to the conclusion that if $f$ and $g$ differ at one point, they cannot have the same Fourier series.
Best Answer
Fourier series (as with infinite series in general) cannot always be term-by-term differentiated. For general series we have the following theorem
Your example fails this theorem dramatically as the derivative of the Fourier series of $x$ do not converge anywhere.
We also have some more specific results. The following theorem gives conditions for which this can be done for Fourier series:
The last condition is not satisfied when the Fourier series has a jump-discontinuity as $x=L$ so we in general we don't expect to be able to term-by-term differentiate a Fourier series that has a jump-discontinuity (thought the theorem does not rule it out). For your example of the Fourier series of $f(x) = x$ the first condition are satisfyed as $f$ is both smooth and continuous on $[-1,1]$ however $f(-1) \not= f(1)$ so the theorem does not apply.
For integration of Fourier series we have the following theorem
Note that the resulting series does not have to be a Fourier series. For example if we have a Fourier series $f(x) = a_0 + \ldots$ with $a_0\not= 0$ then $\int f(x){\rm d}x = a_0x+ \ldots$ and the presence of the $a_0x$ term makes this not be a Fourier series (though for this example one can probably expand $x$ in a Fourier series to get such a series).
The proofs of the theorems above can be found in any good textbook on Fourier series. You can also find them in the following course notes (by P. Laval).