You ask some pretty profound questions. I will answer them as simply as I can. Before I do that, (and by now I seem like a shill for my old professor), I recommend the book from which I learned all of this, Applied Analysis by the Hilbert Space Method by Samuel S. Holland. Despite the lumbering title, it really is an excellent book for undergraduates who have never heard of a Fourier series.
When people speak of a Fourier series, they might speak of something like this
$$f(x) = \frac{a_0}{2} + \sum_{n=1}^{\infty} (a_n \cos{n x} + b_n \sin{n x})$$
Behind this equation, though, buried inside, are some really profound things and assumptions about the very function we have chosen to write this way. There are even profound assumptions behind what the equals sign means!
First of all, what can we say about $f$? Well, because we have chosen to set it equal to a bunch of sines and cosines of increasing frequencies, and those frequencies are just integers, we can say that $f$ must be periodic with frequency $2 \pi$. That is
$$f(x+2 \pi) = f(x)$$
I hope you can see that. To do so, plug in $x+2 \pi$ into the right hand side (RHS). And then plug in something else, like $x+\pi$, and see what happens.
OK, so you can see that not all functions may be written like that; they have to be periodic with period of $2 \pi$. What about the series itself? It is an infinite series, which means that we have to worry about whether it converges. And this is a very sticky point, because Fourier series do not converge to a single point $x$ like Taylor series. I'll talk about why that is in a minute. But, rather, allow me to state mathematically the meaning of the equal sign in the representation of $f$ as a Fourier series:
$$\lim_{N \rightarrow \infty} \int_0^{2 \pi} dx \left [ f(x) - \frac{a_0}{2}- \sum_{n=1}^{N} (a_n \cos{n x} + b_n \sin{n x}) \right ]^2 = 0$$
The integral itself is what we call a mean square error - the average of the square of the error between $f$ and a partial sum. We define convergence not by convergence at a point, but by convergence in an average sense over the interval $[0,2 \pi]$. We do this so that we may speak of representing piecewise continuous objects like square waves, sawtooths, and the like. It turns out that near points of discontinuity, the series may not converge to those points - you may have heard of Gibbs phenomena.
Now, the most important question: how do we determine the coefficients? We go back to the error definition. Define
$$E(a_0,a_1,\ldots,a_N,b_1,\ldots,b_N) = \int_0^{2 \pi} dx \left [ f(x) - \frac{a_0}{2}- \sum_{n=1}^{N} (a_n \cos{n x} + b_n \sin{n x}) \right ]^2 $$
We naturally choose the $a_k$ and $b_k$ so that the error $E$ is a minimum. We simply demand that
$$\frac{\partial E}{\partial a_k} = 0$$
$$\frac{\partial E}{\partial b_k} = 0$$
for all $k \in \{0,1,2,\ldots,N\}$. Let's work with the $b_k$, as the operations on the $a_k$ are nearly identical. We use the fact that we can take the derivative inside the integral (remember, the sum is finite and everything is well-behaved), and we get
$$\frac{\partial E}{\partial b_k} =2\int_0^{2 \pi} dx \left [ f(x) - \frac{a_0}{2}- \sum_{n=1}^{N} (a_n \cos{n x} + b_n \sin{n x}) \right ] (-\sin{k x}) = 0$$
Rearranging this a bit, we get
$$\int_0^{2 \pi} dx \: f(x) \sin{k x} = \sum_{n=1}^{N} \int_0^{2 \pi} dx \:(a_n \cos{n x} + b_n \sin{n x}) \sin{k x}$$
This normally would require us to solve $2N+1$ equations in the $2 N+1$ unknowns, which would make for a terrifying representation. But, we do have one trick up our sleeve: the sines and cosines of integer frequencies are very special in that they satisfy this really cool sifting property:
$$\int_0^{2 \pi} dx \: \sin{n x} \, \sin{k x} = \begin{cases} \\ \pi & n=k \\ 0 & n \ne k\end{cases}$$
$$\int_0^{2 \pi} dx \: \cos{n x} \, \sin{k x} = 0$$
You can prove this to yourself using the sine and cosine addition formulae:
$$2 \sin{a x} \, \sin{b x} = \cos{(a-b) x} - \cos{(a+b) x}$$
$$2 \sin{a x} \, \cos{b x} = \sin{(a+b) x} - \sin{(a-b) x}$$
and noting that the integral of a sine or cosine of a nonzero integer frequency over $[0,2 \pi]$ is zero. Therefore, the coefficients of the series are given by
$$a_n = \frac{1}{\pi} \int_0^{2 \pi} dx \: f(x) \cos{n x}$$
$$b_n = \frac{1}{\pi} \int_0^{2 \pi} dx \: f(x) \sin{n x}$$
Further details and explanations may be found in the book I cited, Chapter 3.