Here proving the necessary condition is trivial, I am not able to prove the sufficient condtion i.e for two ideals A, B of R such that $ AB \subseteq P \implies A \subseteq P$ or$ B \subseteq P $ then P is prime ideal
Now the book has proceeded with taking A=(a) & B=(b) but this could only be true only if A and B are principal ideals.
Am i missing something here?
We are trying to prove a biconditional -- i.e. we need to prove that
$$\forall A,B \trianglelefteq R \; (AB \subseteq P \implies A \subseteq P \text{ or } B \subseteq P) \implies P \text{ is prime}$$ (i.e. the condition is sufficient) and that $$P \text{ is prime} \implies \forall A,B \trianglelefteq R \; (AB \subseteq P \implies A \subseteq P \text{ or } B \subseteq P).$$ (i.e. the condition is necessary). You said that you are able to show the condition is necessary, so let's focus on the proof of sufficiency.
To prove sufficiency, we assume that $\color{blue}{\forall A,B \trianglelefteq R \; (AB \subseteq P \implies A \subseteq P \text{ or } B \subseteq P)}$ and try to deduce that $P$ is prime. To prove that $P$ is prime, we must show that $$\forall a, b \in R (ab \in P \implies a \in P \text{ or } b \in P).$$ So, we let $a, b \in R$ be arbitrary and assume $ab \in P$. Then we wish to show that $a \in P$ or $b \in P$. This is where we use our $\color{blue}{\text{assumption}}$. Setting $A = (a)$ and $B = (b)$, the assumption tells us that $$(a)(b) \subseteq P \implies (a) \subseteq P \text{ or } (b) \subseteq P.$$ We've assumed this implication holds for all ideals $A$ and $B$, so we can choose them to be whatever we like!
Now you must show that $(a)(b) \subseteq P$, and that $$(a) \subseteq P \text{ or } (b) \subseteq P \implies a \in P \text{ or } b \in P.$$ Then you will be able to conclude that $a \in P$ or $b \in P$, as desired.