When do we need to use EJB?
That's your call, but typically when you need services provided by the container. This is an over simplistic answer; because the are alternatives to EJBs that provide the same or similar services, and often you can use container services without needing EJBs, but hopefully you can do a bit of exploring on the back of this and find out more for yourself.
How to implement EJB in our code?
The
JEE tutorial covers this.
what open-source are you combining EJB with?
No short answer to this. What specifically do you mean? e.g. what open source containers are prople using? What third party utilities are they using?
How to setup EJB's containers?
As per their documentation.