It obviously makes sense to travel as much as possible with UZ domestic tariff, so the minimum you can do is Chernivtsi-Lviv by any of UZ trains. The choice here is rather big - #608, #668, #60, #604, #142. Roughly saying 'kupe' (4 person compartment, 2nd class) cost from 69 to 73 UAH depending on train, 'platskartnyi' - from 49 to 53 UAH.
From Lviv you can catch pretty good #35 Lviv-Krakow-Wroclav train (dep. 23:59-arr.5:17, Krakow), cheapest ticket+reservation (2/3) cost a bit less than 40 EUR. Usually no problem with availability even before departure. In order to arrive to Lviv on time it is better to catch train #668 dep. Chernivtsi everyday 15:58 and arriving to Lviv 22:02. Train #60 (Sofia-Bucuresti-Chernivtsi-Lviv-Kyiv) also works, but it arrives to Lviv 23:42 (dep. Chernivtsi 19:02), so it is a bit risky.
If you don't want to spend 40 EUR on direct Lviv-Krakow trains, then it is better to arrive to Lviv in the morning, thus use #604 (dep. Chernivtsi 20:35-arr. 7:41). Afterward you have few choices:
a) either board minibus till the border (Sheguni/Шегині), they depart rather often just in front of the main railways station building. Cost maybe 20 UAH and will take you till the Ukrainian check point in around 2 hours.
b) at 8:47 departs local train (elektrichka, #6109) that will take you also till almost check point, there at 11:20
Then you just cross the border on foot (it is allowed there), from the polish check point (Medyka) there is also multiple minibuses to Przemysl (cost a few PLN). Afterward just use any polish domestic train you like (
http://rozklad-pkp.pl/). Cheaper to use Regio/Osobowy and InterRegio trains, then you can count on fare as low as 31 PLN.
c) if you don't really like the idea of crossing the border on foot and using minubuses to/from the border, then you have a choice to use full scale regular bus Lviv-Przemysl (depart every few hours in the morning, for instance at 8:20, 10:20), cost app. 90 UAH