How much is the ticket debrecen-lvov and return
International return ticket Debrecen-Lviv (2nd class) will cost you 47 euro (or half that for one-way), obviously only when bought in Hungary or Ukraine.
with sleeping cariagge of 3 places?
As of now, 3 bed sleeper reservation Debrecen-Lviv is 12 euro (UZ carriage), but there is information that Russia will cancel (after schedule change in December) their #15 train with which Ukrainian and Russian carriages to Budapest run. Thus situation isn't clear yet what will happen with direct carriages running from Hungary to Ukraine and Russia.
Canay I buy the ticket on line?
No, MAV (Hungarian Railways) doesn't sell tickets to Ukraine online. However in case you really want to have your tickets in advance, you can always purchase online two domestic tickets: a) from Debrecen to Zahony (last station before the border), from 2200 HUF and b) from Chop (first Ukrainian station after the border) to Lviv, here prices start from roughly 2 euro. For the short (15 min.) trip across the border from Zahony to Chop tickets (2,7 euro one-way) are easily bought on spot before departure. As you can see, buying two domestic tickets and one short cross-border one can save you quite a lot of money compared to international ticket price, so if you ok with train changes it might be a good solution