Past
Ilya initially appears as an enemy to Shirō Emiya. The reason she is after him is because his step father, Kiritsugu Emiya, was a Master working for her family in the previous War, but betrayed them by destroying the Holy Grail. After Berserker is defeated, she has no desire to continue fighting and stays at Shirō's house.
She is in reality a Homunculus, an artificial human given life by applying sorcery to sperm cells, originally created and raised by the Einzbern family. She is actually slightly older than Shirō, her childlike appearance being a result of a distorted growth rate. During the Heaven's Feel scenario, it is hinted that the sperm used to create her was donated by Kiritsugu Emiya (it is confirmed in the novel fate/zero), making her his biological daughter and Shirō's step-sister. Her personal interest in Shiro seems conflicted, due to the fact that Kiritsugu, whom she had loved as her father, remained in Japan as Shiro's guardian after betraying her family by destroying the long-sought Grail. Einzbern then trained Ilya harshly in order to groom her as the next vessel for the Grail, and a Master who would finally bring the Grail to the Einzbern family. Ilya, with her mother dying during the Grail War and her father abandoning her shortly after, became angry with Kiritsugu, and consequently, Shiro. She feels that Kiritsugu abandoned her for Shiro, and is jealous of Shiro for that. However at the same time, she also feels very close to Shiro for his relationship with Kiritsugu.
The Einzbern, one of three families of sorcerers involved in the Holy Grail War (the others being the Tōsaka and the Makiri/Matō), were responsible for creation of the vessel which the souls of the defeated Servants would go into, while the Makiri created the system of Masters and Servants and the Tōsaka supplied the land which became Fuyuki City. As such, Ilya was prepared by her family to act as a living vessel for the Grail.
Role
In Fate, Ilya serves as the initial adversary for Shirō and Saber, and eventually ends up living peacefully with Taiga after her defeat. She has her heart torn out by Gilgamesh in Unlimited Blade Works and during Heaven's Feel, she aids Shirō throughout his fight and eventually gives up her body to become the Holy Grail.