The only flaw in your plan is the giant ape part. Polymorph limits you to beasts with a CR equal to or less than the target's. Your imp is only CR 1. A giant ape is CR 7. So that part won't work. But you could polymorph your imp into some other creature of CR 1 or less and then have it attack.