@elhult @maswan There's a few different options. With Deutsche Bahn you can book every trip that starts or ends in Germany, basically, and they tend to have fairly decent rebates if you book early enough. Of course, with trains in general, and DB, DSB, and SJ in particular, being in a bit of a chaotic state at the moment, there's the question how much that helps...
Night trains you need to book ahead, obviously, and usually through the specific company that runs them (ÖBB or SJ, in this case).