Is it possible to take public transport (bus or train) straight from Kobarid, Slovenia to Opatija or Rijeka, Croatia?
Some combination of buses and trains is surely possible, but it may take the better part of a day as it is not a particularly busy route. Rijeka and Opatija really only have good connections with Ljubljana and Trieste, but just getting there from Kobarid will take a few hours. You could get to Postojna and take a train to Opatija and Rijeka from there, but you may find you have to spend the night for the connection to be viable. It is impossible to go into more detail without information on when you plan on travelling. Many trains and buses to the coast only run in the summer months.
This might help.....
The easiest and quickest method would probably be a rental car. Both those destinations are covered on the RS Adriatic tour.