If you rotate the vector i= <1, 0> through angle \theta around the origin. You will get a vector of length 1 which is the hypotenuse of a right triangle. It follows that the "near side", which is the i component of the vector, is cos(\theta) and the "far side", which is the j component of the vector, is sin(\theta). That is, <1, 0> is rotated into <cos(\theta), sin(\theta)>.
Similarly if you rotate the vector j= <0, 1> through angle \theta around the origin. You will get a vector of length 1 which is the hypotenuse of right triangle. This time, the "near side" is along the y-axis while the "opposite side" points in the direction of the negative x axis. The i component is -sin(\theta) and the j component if cos(\theta). <0, 1> is rotated to <-sin(\theta), cos(\theta)>.
As Hurkyl said, you can construct a matrix by using, as columns, the vectors the basis vectors are mapped into. Since <1, 0> is mapped into <cos(\theta), sin(\theta)> and <0, 1> is mapped into <-sin(\theta), cos(\theta)>, the rotation matrix is
\begin{bmatrix}cos(\theta) & -sin(\theta) \\ sin(\theta) & cos(\theta)\end{bmatrix}.
As for three dimensions, it is easy to see that a rotation around the z-axis does not change the z component of any point so rotation around the z axis through angle \theta is given by
\begin{bmatrix}cos(\theta) & -sin(\theta) & 0 \\ sin(\theta) & cos(\theta) & 0 \\ 0 & 0 & 1\end{bmatrix}
and it should be clear that a rotation about the y-axis through angle \theta is
\begin{bmatrix}cos(\theta) & 0 & -sin(\theta) \\ 0 & 1 & 0 \\ sin(\theta) & 0 & cos(\theta)\end{bmatrix}
and a rotation about the x-axis through angle \theta is
\begin{bmatrix}1 & 0 & 0 \\ 0 & cos(\theta) & -sin(\theta) \\ 0 & sin(\theta) & cos(\theta)\end{bmatrix}
Finally, to rotate around a general vector, <a, b, c>, through an angle \theta, find a matrix, A, that rotates the axis, <a, b, c>, around the z-axis into the yz-plane so that the i component is 0. It is easy to see, with a little work, that the matrix that does that is
\begin{bmatrix}\frac{b}{r} & -\frac{a}{r} & 0 \\ \frac{a}{r} & \frac{b}{r} & 0 \\ 0 & 0 & 1\end{bmatrix}
where r= \sqrt{a^2+ b^2}.
Next, rotate around the x-axis so that axis is rotated into the z-axis. That requires matrix
B= \begin{bmatrix}1 & 0 & 0 \\ 0 & \frac{c}{\rho} & -\frac{r}{\rho} \\ 0 & \frac{r}{\rho} & \frac{c}{\rho}\end{bmatrix}
Once you have done that, use the matrix
\begin{bmatrix}cos(\theta) & -sin(\theta) & 0 \\ sin(\theta) & cos(\theta) & 0 \\ 0 & 0 & 1\end{bmatrix}
Finally, use the inverses of matrices B and A to rotate back to the original position. Of course, the inverse matrix just rotates through the negative angle- and since cosine (the diagonal elements) is an even function while sine (the off diagonal elements) is an odd function, that just requires changing the sign on the off diagonal elements.
That is, to rotate a vector through angle \theta, around axis <a, b, c> multiply by the matrix product:
\begin{bmatrix}\frac{b}{r} & \frac{a}{r} & 0 \\ -\frac{a}{r} & \frac{b}{r} & 0 \\ 0 & 0 & 1\end{bmatrix}\begin{bmatrix}1 & 0 & 0 \\ 0 & \frac{c}{\rho} & -\frac{r}{\rho} \\ 0 & \frac{r}{\rho} & \frac{c}{\rho}\end{bmatrix}\begin{bmatrix}cos(\theta) & -sin(\theta) & 0 \\ sin(\theta) & cos(\theta) & 0 \\ 0 & 0 & 1\end{bmatrix}\begin{bmatrix}1 & 0 & 0 \\ 0 & \frac{c}{\rho} & -\frac{r}{\rho} \\ 0 & \frac{r}{\rho} & \frac{c}{\rho}\end{bmatrix}\begin{bmatrix}\frac{b}{r} & -\frac{a}{r} & 0 \\ \frac{a}{r} & \frac{b}{r} & 0 \\ 0 & 0 & 1\end{bmatrix}