There exists an algorithm to find grammar of complement of a function?
Contrary to what you wrote, context-free languages are not closed under complement.  See Examples of context-free languages with a non-context-free complements for some examples.  As a result, there is no such algorithm.

Also: It's decidable whether $L(S)=\emptyset$, but it's not decidable whether $L(S)=\Sigma^*$.  If you could compute the complement, then you could decide the latter using the algorithm for the former.

In contrast, deterministic context-free languages are closed under complement, and the proof of that fact likely identifies an algorithm that will work when you have a deterministic context-free language.  Another way to handle it: convert to a deterministic pushdown automaton, then it is clear how to complement it.