Does the position operator have enough eigenfunction to span the whole Hilbert space? For a particle in a well, the energy eigenfunctions are in the form,
$$\psi(x)=\sqrt\frac{2}{a}\sin\bigg(\frac{n\pi}{a}x\bigg)$$
And from Fourier theorem, which says that any function can be represented by a linear combination of sine functions. Therefore eigenfunction can span the Hilbert space.
In David J Griffiths, Introduction to Quantum Mechanics Second Edition, p. 131 Eqn. 3.75, he mentions that

The wave function $\Psi(x,t)$ is actually the coefficient in the expansion of $|\mathcal S\rangle$ in the basis of position eigenfunctions: $$\Psi(x,t) = \langle x|\mathcal S\rangle$$

where $|\mathcal S\rangle$ is the state vector. How can we be sure that the position operator has enough eigenbasis to span the whole Hilbert space.
For instance, say, that a operator $A$ is defined as,
$$A=\begin{bmatrix} 1&1\\0&1\end{bmatrix}$$
has eigenvalue 1 and a eigenvector $\begin{bmatrix}1\\0\end{bmatrix}$ which is not enough to span the 2D space.
Similarly, how can we be sure that the eigenvectors of the the position operator can span the whole space? Also, is it a coincidence that the eigenbasis of the Hamiltonian are orthogonal to each other?
 A: The answer to your question is the spectral theorem. Roughly, it says that any self-adjoint operator (that is, one satisfying $A^\dagger = A$ plus some other things when the dimension is infinite) has a basis of orthogonal eigenvectors with real eigenvalues. The proof you can find all over the internet or in books about linear algebra and/or functional analysis.
This theorem is the reason we ask that our observables like position or energy be self-adjoint; we want to have real eigenvalues (because we measure real numbers) and we want to have a basis of eigenvectors, like you mention. In your example, $A$ is not hermitian (= self-adjoint in finite dimension), so it doesn't have an orthogonal basis of eigenvectors -- it is not even diagonalizable.

Edit: as per DanielSank's suggestion, since the title explicitly asks about the position operator I'll take a look at that specific case.
We need to show that it is self-adjoint. In fact, in infinite dimensional spaces the distinction between Hermitian and self-adjoint is quite subtle; this is made worse by the fact that Hermicitiy is easy to prove, but self-adjointness is what we care about. I'll just give a simple "proof" that simply ignores all complications.$^1$
Let $(|\phi\rangle, |\psi \rangle)$ denote the inner product between states $|\phi\rangle$ and $|\psi\rangle$; we want to show that for any pair of states, $(|\phi\rangle, \hat{x}|\psi\rangle) = (\hat{x}|\phi\rangle, |\psi\rangle)$. This is easy, since the left hand side is
$$\int dx\ \phi(x)^* x \psi(x)$$
while the right hand side is
$$\int dx\ (x\phi(x))^*\psi(x)$$
and these two are equal.

$^1$ In fact, $\hat{x}$ doesn't actually have any eigenvectors! This is because delta functions don't belong to the Hilbert space $L^2(\mathbb{R})$. This is not usually a problem, but if you want to be rigorous about this you should look at rigged Hilbert spaces which include "generalized eigenvectors".
