Okay, I think I understand the situation now. Sorry to ask so many questions but sometimes it is necessary.
There are several issues here. The way I first understood, I thought that you had custody of the children all year. However, it appears that the children only lived with you until July, but lived with their mother all year. As such, the children are qualifying children of both you and their mother, but she meets the definition of custodial parent.
The grandmother has no legal basis to claim the children, because the children lived with her for less than 1 year, and as such they are not her "qualifying children". You cannot claim a dependent that is a qualifying child of another taxpayer.
There are certain rules for children of divorced or separated parents, but these rules do not apply because they require the parents to live apart during the last 6 months of the year.
So, The children are "qualifying children" of both you and their mother. As such, if both of you claim the same children, the tie-breaker rules will kick in and she will be awarded the right to claim them because they resided with her for the longer part of the year. If you and the grandmother both claim the children, you have the higher right to the claim because they are your qualifying children.
If the mother did work for part of the year, she may claim the children and receive earned income credit--which can provide her with a large refund. However, depending upon what she earned, it may not benefit her to claim all three children. Therefore, you should work out with her which children you will each be claiming.