key specifications for x25519 - need two clarifications please
About your first question, yes, the set of private keys is restricted to those $2^{251}$ values that are always a multiple of $8$ and that's security by design:


By making sure the input scalar of the scalar multiplication algorithm is a $255$-bit value will the algorithm specified in the RFC will always perform 254 loops and each of those loops will perform the exact same operations (one addition, one doubling): it's a simple protection against simple side-channel analysis
To prevent against the invalid point attack (Bob giving to Alice a point of low order on another curve), only the $x$-coordinate is used, so the point belongs either to the curve or its quadratic twist. The only points of low order on those curves have order $2$, $4$ or $8$, so if Bob submits one of those, Alice will always get $0$ (representing the infinity point in the X25519 function) as an output of the key-exchange and detect that it is invalid. Invalid point attack and small subgroup attack are prevented.


You might want to read the original papers on it: Curve25519:new Diffie-Hellman speed records and Can we avoid tests for zero in fast elliptic-curve arithmetic?

About your second question, it is just fast exponentiation. Look at the binary decomposition of $p-2 = 2^{255} - 19 - 2$. Or look at some already written code (most of Curve25519 implementation come from the same reference).