To speak about this precisely, one has to built up the setting a bit more carefully. It is also a bit of an abuse to use the term Hilbert space since this functions are not formally a basis for the space, given that they are not normalizable. So I would suggest, to gain some insight on your question, to consider instead of $x\in(-\infty,\infty)$, take $x\in[-1,1]$. Along with the condition of $f$ being square-integrable. Eventually this is called $\mathcal{H}=\mathcal{L}^2([-1,1])$ which is a proper Hilbert space. It turns out that the Fourier transform is a unitary automorphism of this space, so that you can think of $x$ and $p$ as two bases (see https://en.wikipedia.org/wiki/Fourier_transform#On_L2). One can then realize the dual space $\mathcal{H}^*$ is itself and treat $\mathcal{H}$ in let's say $p$ coordinates and $\mathcal{H}^*$ in $x$ coordinates while the relation being the automorphism. A bit Functional analysis will serve the purpose of explaining all this in detail. (The formalism is always deeper in comparison to how the concepts are discovered)
The physical(ist) approach (I will ignore factors of $2\pi$, so forgive me for that :) ) is looking to solve the eigenfunction equation of the momentum operator (obviously real values, since that is what one can measure in the lab) and build a complete base out of it. Once you have solved for the eigenfunctions as above, you should be able to express any state, even $| x\rangle$ in this new base. So what you do is project into every basis element $|p\rangle$.
$$|x\rangle = \int dp |p\rangle \langle p|x\rangle$$
However you have implicitly imposed the Fourier relation when you were solving the eigenfunction equation, since
$$-i\hslash \frac{d}{dx}f_p(x) = p f_p(x)$$
is turned into through a Fourier transform (including the $\hslash$ in the kernel), which
$$p'\tilde{f}_p(p') = p \tilde{f}_p(p')$$
which is solved by picking $p=p'$ (so we can drop the subindex $p$ on the Fourier version while adding the subscript to the $x$ position to which it is associated, as written below), which is basically telling you any function of just $p$ can be converted into an eigenfunction if you transform it via a Fourier transform back to $x$. Up to this point you could pick any set of those functions (depending just on $p$) to be your new basis. So that if you wanted to write this functions in terms of $x$ then you employ the inverse Fourier transform to get:
$$f_p(x) = \int dp\; e^{ipx/\hslash}\tilde{f}(p)$$
And where as pointed out before, $\tilde{f}(p)=\langle p|f\rangle$ is the projection of $f$ into the basis labeled by $p$.
Having imposed that the relation between the coordinates is a fourier transform and demanding orthonormality, you can determine suitable $f$'s.