"Best ways" is kind of relative here, since on some cases there aren't many options to begin with, especially when it comes to rail transport
Between Albania and Montenegro there is no passengers train service, so as far as you can get by train in Albania is Shkoder, while from there you can take bus to Montenegro (buses from Shkoder to Ulcinj run few times per day). Also it has been reported that there are some semiofficial transport directly from Tirana to Ulcinj, however for the up to date info on that it will be better to ask already in Tirana (e.g. hotel management in Tirana would probably help here).
From Ulcinj you have two options: a) travel directly to Sarajevo (apparently during summer season there is daytime (7:30-17:20) and overnight (20:00-6:30) direct buses) or b) first travel to Podgorica and from there take one of the multiple buses to BiH capital (bus schedule Ulcinj-Podgorica and Podgorica-Sarajevo can be found
here)
With Sarajevo to Ljubljana you also can not count on direct train, however with one change in Croatia (Zagreb) the journey is pretty easy. First direct train from Sarajevo to Zagreb (10:46-19:51) and then another one from Zagreb to Ljubljana (21:20-23:37). In case you don't want to spend entire day for the journey, then also possible to take direct overnight bus from Sarajevo to Ljubljana (however night on the bus might not be the most desired option)