Our ahadith have divided sleeping into four types in which the best of all of them for the believer is to sleep on his right and towards the Qibla.
Imam Ali (a) is narrated to have said: “Sleeping has four types: The Prophets (a) would sleep on their backs, their eyes would not sleep, and they were in a constant state of expectation of divine revelation. The pious person sleeps on their right side and faces the Qibla in this state. The kings and their children sleep on their left sides so that what they have ate will be refreshing to them. Then the Satan, his brothers, and every crazy and sick person sleeps on their stomachs.”
Imam Sadiq (as) has been narrated saying: “Barra’ bin Ma’rur Ansari was in Medinah and the Prophet of Islam in Makkah when the time for Barra’s death arrived (this was the time when the Muslims were praying towards Jerusalem). He asked for his face to placed in the grave facing Makkah where the prophet (pbuh) was. He also determined what was to be done with one third of his wealth. This became a custom from then on.” It is on this basis and other fiqhi reasons that the faqihs have issued fatwas that “The dead person must be laid on his right side such that the front of his body is facing the Qibla”.
This question can be divided into two sections and we will answer them with the same breakdown. The first section of the question dealt with sleeping or resting while facing the Qiblah. To begin it is a reality that Islam is the last revealed religion which was sent down from God in order that people can reach guidance and human perfection.  From this perspective it is essential that this religion which is complete  should meet the needs of all human beings, whether small or big.  Based on this Islam has a set of rules for sleeping as well. These rules are not obligatory (Wajib), but they are a sort of recommendation (Mustahab) which will be the best for people if they follow them. Below we will mention a few of them.
Imam Hadi (a) said: “We, the Ahlul Bait, when going to sleep, pay attention to ten things: having taharat, putting the face on the palm of the right hand, saying Subhannallah 33 times, saying Alhamdullillah 33 times, and saying Allaho Akbar 34 times, sleeping while facing the Qiblah in such a way that our faces are towards the Qiblah, reciting Surah Hamd and the Ayatul Kursi and the Verse of Shahidallah….  So whoever does these things has gained his share from that night. 
The Various Forms of Sleeping
In Shia traditions sleeping has been divided into 4 sections, of which the best kind for the pious Muslims is for him to sleep on his right side while facing the Qiblah. Abdullah Bin Ahmad bin Aamer Taa’ee narrated from Imam Ridha (a) who narrated from his father who narrated from Imam Hussain Ibn Ali (a) who said: “Ali Ibn Abi Talib was in the Masjid of Kufa when a man from Shaam stoop up and asked him certain questions. Among the various questions he asked one of them was this that: “I would like to know how many different types of sleep exist?” Imam (a) replied: “Sleeping has four types: The Prophets (a) would sleep on their backs, their eyes would not sleep, and they were in a constant state of the expectation of divine revelation. The pious person sleeps on their right side and faces the Qibla in this state. The kings and their children sleep on their left sides so that what they have eaten will be refreshing to them. Then the Satan, his brothers, and every crazy and sick person sleeps on their stomachs.” 
As for the second part of the question which asks about burying of the dead while facing the Qiblah it has to be said that Islam has sets of rules and guidelines for every step and stage of human life. This includes from even before conception to the time when someone is at the doorsteps of death. There are rules even for the way someone should be buried and wrapped in their burial shroud. Later we will mention some of these issues in detail.
Imam Sadiq (a) has said: “If someone who is in the state of dying is having a lot of difficulty and pain, they should be taken to their usual place of prayer.” In another tradition it is narrated that: “If someone is in the state of dying and they are facing a lot of pain and suffering in this state, take them to their place of prayer or place them upon their prayer rug.”
In regards to situating someone to face the Qiblah during the time of dying Imam (a) has said: “If anyone amongst the Shias is on the threshold of dying then take his legs and place them so that they face the direction of the Qiblah and cover him. Then during the time of giving someone a Ghusl, dig a hole in the ground which is facing the Qiblah and put the stretcher which the dead individual is placed on over that excavation in a way that his legs and face are facing the Qiblah.” 
In regards to turning the dead individual towards the Qiblah there are multitudes of traditions in the book Wasa’ilul Shia. In fact there are so many that they have merited a section exclusive to themselves. These hadiths narrate that you should place the dead body in the grave in such a way that they are lying on their right hand and their face is in the direction of the Qiblah. One example of these traditions is as follows: Imam Sadiq (a) has said: “Barra’ bin Ma’rur Ansari was in Medinah and the Prophet of Islam in Makkah when the time for Barra’s death arrived (this was the time when the Muslims were praying towards Jerusalem). He asked for his face to placed in the grave facing Makkah where the prophet (pbuh) was. He also determined what was to be done with one third of his wealth. This became a custom from then on.  So based on this and some other reasons the ‘Fuqaha’ ruled that the dead should be placed on their right sides (in the grave) and that they should lie in such a way so that the front of their bodies are facing the Qiblah. 
 In this regard, you can refer to Question 5222 of this website.
 If a new and unprecedented issue comes up (Masa’el Mustahdathah) the great Islamic scholars can derive its ruling from Islamic sources using general principles of jurisprudence.
 Ale Imran:18.
 Husein, Ostad Waliyy, Adab, Sonan va Raveshe Raftariye Payambare Geramiye Eslam, pg. 80.
 Sheikh Saduq, Al-Khisal, vol. 1, pg. 262; Sheikh Saduq, Uyun Akhbarul-Ridha (Ghaffari wa Mustafid), vol. 1, pg. 510.
 Kuleini, Kafi, vol. 3, pg. 127.
 Sheikh Hurr Ameli, Wasa’elul-Shia, vol. 3, pg. 231.
 Tawdihul-Masa’el, vol. 1, pg. 339, issue 615.