I use to have this problem when I first put the engine in the Sonata.. When the car was revving, it would be fine, but when you would idle it would stall...
Off memory, it was the idle switch... When we upgraded the ecu and put in the aftermarket intake it never happened.... But it sounds like all you may have to do is just adjust the idle... If that does not fix it, maybe it is an ECU thing, and may require it to be looked at or reset...