The bus from Trieste (you can take the ferry there, half an hour) takes nine hours. The train or the bus from Ljubljana takes eight hours -- and you need to get there first which takes two hours on the bus. So far everything takes ten hours. The only way to save time is to get to Ljubljana but from there take a car share. You'll have tons of options because everyone driving from Italy to Hungary these days will go through Slovenia / Ljubljana. Instead of eight hours the Ljubljana-Budapest section will take only five, a grand total of seven hours. Given the drive from Portoroz to Budapest alone takes about six hours it'd be hard to find a quicker option. It is also cheap.
And, whatever "best" means for you, I am unaware of any other even remotely sane options. Flying from Trieste is out because you'd need to connect and thus doesn't save much time. Same for Ljubljana.
This answer is correct as of May 6, 2015 but the train line is part of an EU corridor so it will get faster later. The Hodoš-Pragersko section was just rebuilt up to 160 km/h but that's a short part of the long train ride. Here's a 2016 March 8 report from the Slovenian government on these matters.