You always start from the first and second law of thermodynamics, i.e.,
[tex]\mathrm{d}U=T \mathrm{d} S-p \mathrm{d} V+\mu \mathrm{d} N.[/tex]
Here, [itex]U[/itex] is the internal energy, [itex]T[/itex] the temperature, [itex]S[/itex] the entropy, [itex]p[/itex] the pressure, [itex]V[/itex] the volume, [itex]\mu[/itex] the chemical potential, and [itex]N[/itex] a (conserved!) particle-number like quantity. In nonrelativistic physics often you can take [itex]N[/itex] as the particle number itself, while in non-relativistic physics usually there are only conserved charges like elecctric charge, net-baryon number, etc. Here, we just consider the case of one such particle-number like quantities and thus only one chemical potential. The generalization to more variables is straight forward.

The above equation shows that the "natural" independent variables for the internal energy are [itex]S[/itex], [itex]V[/itex], and [itex]N[/itex]. Since by construction [itex]\mathrm{d} U[/itex] is a total differential, you read off relations like
[tex]\left (\frac{\partial U}{\partial S} \right)_{V,N}=T.[/tex]
Here, the variables listed in the subscript indicate which variables have to be kept constant when differentiating. It's pretty important in this business to keep track of what's left constant when taking partial derivatives of the various quantities. Since from [itex]U[/itex] you can derive other quantities by taking partial derivatives one calls [itex]U[/itex] a thermodynamical potential, and which other quantities you get by taking derivatives in the most straight-forward way is determined by what are the "natural" independent quantities to use as explained above.

Let's now look at the entropy. From the equation above we get
[tex]\mathrm{d} S=\frac{1}{T} \mathrm{d} U+\frac{p}{T} \mathrm{d} V-\frac{\mu}{T} \mathrm{d}N.[/tex]
The "natural" independent variables to be used together with the entropy are thus [itex]U[/itex], [itex]V[/itex], and [itex]N[/itex], and the corresponding partial derivatives wrt. to one of these three variables (keeping precisely the other two fixed) are the coefficients in front of the differentials. Again we use the argument that [itex]S[/itex] is a state variable and thus [itex]\mathrm{d} S[/itex] is a total differential. For the following it's convenient to introduce new variables, namely
[tex]\beta=1/T, \quad \alpha=\mu/T.[/tex]
Then we have
[tex]\mathrm{d} S=\beta \mathrm{d} U+\frac{p}{T} \mathrm{d} V -\alpha \mathrm{d} N.[/tex]
With a Legendre transformation you define new quantities such that other variables become the "natural" independent variables. Let's start with the first example. You are supposed to find a Legendre transformation of [itex]S[/itex] such that the natural quantities become [itex](\beta,V,N)[/itex]. Now, for the enropy [itex]V[/itex] and [itex]N[/itex] are already natural variables, but not [itex]\beta[/itex], but we have the relation
[tex]\beta=\left (\frac{\partial S}{\partial U} \right )_{V,N}.[/tex]
Now to make [itex]\beta[/itex] a natural variable of another quantitiy, you simply have to define the new quantity as
[tex]X=S-\beta U[/tex]
Then from the above given differential you have
[tex]\mathrm{d} X=\mathrm{d} S - \mathrm{d}(\beta U)=\mathrm{d} S - U \mathrm{d} \beta-\beta \mathrm{d}U = \frac{p}{T} \mathrm{d} V-\alpha \mathrm{d} N-U \mathrm{d} \beta.[/tex]
Now obviously the natural variables for [itex]X[/itex] are indeed [itex](\beta,V,N)[/itex].

As next step you want still a new quantity such that the natural variables are [itex]\beta,V,N[/itex]. Now you read off the last equation
[tex]\left (\frac{\partial X}{\partial N} \right)_{\beta,V}=-\alpha.[/tex]
Thus, by another Legendre transform you see that the searched quanity must be
[tex]\Omega=X+\alpha N=S-\beta U+\alpha N[/tex]
since this leads to
[tex]\mathrm{d} \Omega=\frac{p}{T} \mathrm{d} V+N \mathrm{d} \alpha-U \mathrm{d} \beta.[/tex]
That's the grand-canonical potential with the natural independent variables [itex]V, \quad \beta, \quad \alpha[/itex].

The goal is to make a new function, [itex]\tilde{f}(p)[/itex], of a new variable, [itex]p[/itex], and, in doing so maximize
[tex]
xp-f(x)
[/tex]
for a given value of [itex]x[/itex]. To maximize anything we have drilled in us to take the derivative and set it equal to zero
[tex]
xp-f(x)\implies p=\frac{df(x)}{dx}\equiv g(x)
[/tex]
where I renamed the derivative as a new function, [itex]g(x)[/itex]. Now we are interested in the [itex]x[/itex] that maximizes the first expression, so we solve for [itex]x[/itex]
[tex]
x=g^{-1}(p)
[/tex]
then
[tex]
\tilde{f}(p)=p \, g^{-1}(p) - f \left( g^{-1}(p) \right)
[/tex]
this is the new function. Now let's start with the expression for [itex]p[/itex].
[tex]
p=\frac{df}{dx}\implies p \, dx = df \implies d(px) - x \, dp = df \implies d(xp-f) = x \, dp
[/tex]
which is true by looking back to the first part. So you can revert back and forth between [itex]x[/itex] and [itex]p[/itex] with this little "reverse product rule" move. You can try it on your thermodynamic pair of choice. Like [itex]TdS = d(TS) - S \, dT[/itex] and you can reshuffle the total differentials to make it look nice :)