That's an interesting one, SFB.
Your sentences seem to have several possible uses, depending on context:
1. I'm wondering if I CAN replace A with B.
— oblique request for an opinion about replacing A with B. "Do you think I should replace A with B?"
2. I'm wondering if I CAN replace A with B.
— oblique request for permission to replace A with B. "May I replace A with B?"
3. I'm wondering if I CAN replace A with B.
— sudden realization: 'it may be possible to replace A with B'. "What if I replace A with B?"
4. I'm wondering if I CAN replace A with B.
— sudden doubt as to own capacity to replace A with B. "Am I able to replace A with B?"
5. I'm wondering if I COULD replace A with B.
— oblique request for an opinion about replacing A with B. Slightly more doubting version of #1.
6. I'm wondering if I COULD replace A with B.
— request for permission to replace A with B; more deferential/polite than #2. "Might I replace A with B?"/"Would I be able to replace A with B?"
7. I'm wondering if I COULD replace A with B.
— sudden realization: 'it might be possible to replace A with B!'. Version of #3: "What if I were to replace A with B?"
8. I'm wondering if I COULD replace A with B.
— sudden doubt as to own capacity to replace A with B. Version of #4. "Would I be able to replace A with B?"
As Katsu says, as a rough rule of thumb, CAN gives an impression of more immediacy, whereas COULD distances the action a little.
No doubt there are other possibilities!
MrP
PS:
9. I'm wondering if I CAN replace A with B.
— doubt as to possibility of replacing A with B. "Maybe it isn't possible to replace A with B."
10. I'm wondering if I COULD replace A with B.
— doubt as to possibility of replacing A with B. "Maybe it wouldn't be possible to replace A with B."