From Stockholm to Oslo Swedish Railways (SJ) offers tickets from 95 SEK, but you have to book early in advance. Prices go up as later you buy. So, buy your ticket as soon as you know when you are going. Unfortunately online-booking only works if your credit card has 3D-Secure enabled or if your credit card is issued by a nordic bank. So, most of you simply cannot book online. Just buy all your SJ tickets already when you get the first time to an SJ office or at the SJ ticket machines in Copenhagen Central Station, Copenhagen Airport or Oslo Central Station.
In Oslo you have two possibilities to buy a ticket to Stockholm. You can buy from the ticket office of Norwegian Railways (NSB), or you can buy from the ticket machine of Swedish Railways (SJ). Prices are probably different for the same train. I cannot tell you at the moment which is cheaper. But usually if you book long time in advance SJ should be cheaper.