I was wondering what does it mean when time series residuals have autocorrelation? How should I deal with it?
Since this is a very comprehensive topic, you will have to do research on model checking within the Box-Jenkins framework by yourself, but I try to give a short answer to your short question:
In general, after fitting a time series model (at least you are using a standard model and not assuming a special individual model, where the residuals may behave differently) the residuals should be white noise. So they should have no autocorrelation. If you have significant autocorrelation (you have to test this) and not just one spike at high lag order in your acf/pacf this maybe an indicate that you specified your model wrong. It depends, you could for example plot the residuals along with your other variable in a scatter plot and look, e.g. if there is still a seasonal behaviour, but you should also definitely also test this. If the autocorrelation is significant, yes, this is a problem, since this implies, you missed to include some information. So e.g. your lag order is not sufficient. If the autocorrelation turns out to be not significant, this is not a problem.
So the answer: Test it. See: How to test the autocorrelation of the residuals?
If this answer satisfies you, it would be nice, if you click on the left hook to my post and accept my post as the answer.
Following Stat Tistician's suggestion, the solution is to use Regression Model with ARIMA error .
library(nlme) #create some fake data with AR4 noise n=500 set.seed(42) v = arima.sim(list(ar=c(0.2,0.2,0.2,0.2)), n) x= seq(-3,3,length.out = n) y = 0.5*x + 2*v + 0.5*rnorm(n) #fit summary(gls(y~x, correlation = corARMA(form = ~1, p=4,q=0)))