The second part of your question is already noted by Peter, which is fairly simple in implementation. I focus more on the first part of your question which can sometimes be more complex depending on the issue.
The easiest "test" of correlated errors is often just knowing what your correlational structures should be ahead of time. We should safely assume anything that can be partitioned into a group with shared characteristics will share some kind of correlational structure, each of which will have varying effects on the errors. Repeated measures and time series are the two most obvious types of data which will specifically have autocorrelation. How deeply correlated with the errors they are and how much that matters will vary, but modeling them directly certainly addresses much of this.
The typical way to check for autocorrelation is, as you say, some kind of autocorrelation function (ACF) plot or if needed a partial autocorrelation function (PACF) plot, shown below with clearly patterned residuals. A very simple simulated example of autocorrelated data and the ACF plot to detect it is written in R below, where the ACF plot shows an average autocorrelation of $.70$. The original source code is from here, but I annotate the code heavily to explain what its doing.
#### Set Seed ####
set.seed(123)
#### Simulate Autocorrelation ####
ar.epsilon <- arima.sim( # simulates time series
list( # list to store info
order = c(1,0,0), # simple AR(1) model with no differencing, etc.
ar = 0.7 # level of autocorrelation
),
n = 200, # number of observations
sd=20 # fluctuation
)
#### Simulate Data for Model ####
x <- rnorm(200) # normally distributed x
y = 50 + 25*x + ar.epsilon # intercept, slope, and autocorrelated residuals
df <- data.frame(x=x, y=y) # store data here
#### Fit Model ####
lm.mod <- lm(y ~ x, data=df) # fit model
#### ACF Plot ####
acf(resid(lm.mod), # take residuals from model
main = "ACF Plot of Residuals") # title
There also exist formal tests of autocorrelation like the Durbin-Watson or the Ljung-Box test, but I find such tests to be less useful than residual plots, and tests like these are known to have some problematic features. One important question you noted here:
Do we simply perform the autocorrelation between the function res($X$)
and it shifted version res($X$ + $\delta X$)
?
This will depend on the nature of your data. Often we can simply run the ACF or PACF plots on our residuals directly and examine away (one can adjust the amount of lag in these functions depending on the need). However, sometimes the residuals will have complex structural autocorrelation that is not easy to detect. Probably the easiest example of that is human trial data, where things like non-randomized trials can lead to people guessing more easily what the next trial will be and thus create correlated errors. Shown below are such trial autocorrelations, as explained in this article:
As shown, you would need to check by-subject ACF plots to determine if there are heavily correlated errors between trials which warrant concern, which one can program from the article above. Some implementations of time series in psychology may also be instructive of when these things pop up in human research which may not be "typical" time series.