I see two steps
1 -- MODEL SELECTION
Here we use a train and a test error to select a model.
In this contest, model refers to a the mathematical formulation of a solution (a function $\hat f (x, \theta)$) rather than a specific instance of a model where every parameter ($\theta$) has been set. Or, in other words, the performance of a method of producing a model, not of the model itself (see)
In this step. You will deal with test and train error. That is residuals on the test and train data. The analysis should take into account and discriminate between test and train.
You can read about the bias/variance tradeoff here.
I would also recommend
In a nutshell (source):

2 -- MODEL FITTING
In this phase, after having selected a model, we fit it to the data. In case of a simple linear regression, we can find the $\theta$ that minimizes the cost function.
Here we make use of the whole dataset. We make use of the whole dataset because we have already analyzed how a model generalizes and the risk of overfitting in step 1. Now it is time to estimate $\theta$ and the more data we have, the better it is.
I believe that it is in this context that it is meaningful speaking of prediction and confidence intervals.
I mention here the two because they are often confused.
Although both are centered at $\hat y$, the prediction interval is
wider than the confidence interval, for a given $x$ and confidence
level. This makes sense, since the prediction interval must take
account of the tendency of y to fluctuate from its mean value, while
the confidence interval simply needs to account for the uncertainty in
estimating the mean value (source)