Romans 11:1 And so I ask: Has God rejected his people? Of course not! I, myself, am an Israelite, a descendant of Abraham, from the tribe of Benjamin. 2 No, God has not rejected the people he knew beforehand. Don’t you know what the Scripture says of Elijah, when he was accusing Israel before God? 3 He said: “Lord, they have killed your prophets, destroyed your altars, and I alone remain; and now they want to kill me.” 4 What was God’s answer? “I kept for myself seven thousand who did not worship Baal.” 5 In the same way, now, there is a remnant in Israel, those who were chosen, by grace. 6 It is said: by grace, not because of what they did. Otherwise, grace would not be grace.
The passage above is about a remnant in the nation of Israel that is like the seven thousand remnant in Israel in Elijah's time and their choosing by God which was by grace and not by works. God did not choose the remnant of Israel because they did something that made the choice a necessity or a payment for work done. Nevertheless the seven thousand "did not worship Baal". The remnant in saint Paul's time are chosen by grace and not because of works that they did.
Ephesians 2:7-10: 7 In showing us such kindness, in Christ Jesus, God willed to reveal, and unfold in the coming ages, the extraordinary riches of his grace. 8 By the grace of God, you have been saved, through faith. This has not come from you: it is God’s gift. 9 This was not the result of your works, so you are not to feel proud. 10 What we are, is God’s work. He has created us, in Christ Jesus, for the good works he has prepared, that we should devote ourselves to them.
Salvation is God grace gift which is given through faith for the purpose of making a people who devote themselves to doing the good works that God prepared for them. There's no contradiction between the two passages. Grace does not preclude works it simply is not given on the basis of works but it is evident that grace leads to good works because that is its purpose; specifically, God has created us, in Christ Jesus, for the good works he has prepared, that we should devote ourselves to them.