If we assume that
$$
{\rm E}[\varepsilon | X] = 0,
$$
then the regression coefficients are still calculated as
$$
\hat{\beta} = (X^TX)^{-1}X^TY.
$$
The variance of $\hat{\beta}$, however, is no longer the same as the one in the deterministic case since expression
$$
\sigma^2(X^TX)^{-1} =: {\rm Var}[\hat{\beta} | X]
$$
is now a random variable. To calculate the overall, unconditional variance of $\hat{\beta}$, we use the rule
$$
{\rm Var}[\hat{\beta}] = {\rm E}[{\rm Var}[\hat{\beta} | X]] + {\rm Var}[{\rm E}[\hat{\beta} | X]].
$$
The landmark book by
... Greene, W. H. (2011). Econometric Analysis (7th ed). Upper Saddle River, NJ: Prentice Hall.
covers the case of stochastic predictors in detail in the earlier chapters.