Replacing improper integral by sum of integrals

If the left hand side converges, then the right hand side converges. But not the converse. For example, if $f(x) = \sin(x)$ and $a = 2\pi$, then the right hand side is $0$, and the left hand side is undefined. If $f$ has a finite number of infinite values, you can handle them one at a time, and what you do on the left hand side is the same as what you do to the right hand side.

If the left hand side converges, we have $$ \lim_{R \to \infty, S \to -\infty} \int_S^R f(x) \, dx = L .$$ So we can restrict $R$ and $S$ to multiples of $a$ to see $$ \lim_{n \to \infty, m \to -\infty} \int_{am}^{an} f(x) \, dx = L ,$$ and $$ \int_{am}^{an} f(x) \, dx = \sum_{k=m}^{n-1} \int_{ka}^{(k+1)a} f(x) \, dx .$$ Next, if, say, $\lim_{x\to b-} f(x) \, dx = \pm\infty$, then for the left hand side you add in $$ \lim_{u\to b-, v\to b+} \int_S^u + \int_v^R f(x) \, dx ,$$ and for the right hand side you pick the $n$ such that $na < b < (n+1)a$, and instead of $$ \int_{na}^{(n+1)a} f(x) \, dx $$ use $$ \lim_{u\to b-, v\to b+} \int_{na}^u + \int_v^{(n+1)a} f(x) \, dx ,$$ or if $b = na$, then instead of $$ \int_{(n-1)a}^{na} f(x) \, dx + \int_{na}^{(n+1)a} f(x) \, dx $$ use $$ \lim_{u\to b-, v\to b+} \int_{(n-1)a}^u + \int_v^{(n+1)a} f(x) \, dx ,$$


This is true as soon as $f$ is Lebesgue integrable... which makes sense if you speak of $\int_{-\infty}^\infty f(x) dx$.

The equality is just a particular case of Lebesgue countable additivity property.