Those are profound questions. What is necessary in order for something to have emotions is an aspect of the question of what is necessary in order for something to be conscious – the defining feature of consciousness is the ability to have subjective experience, and emotion is one type of subjective experience. The question of how exactly consciousness arises in the universe has been called by some as the greatest unanswered scientific question. The Hard Problem of Consciousness asks how atoms, which do not possesses the property of consciousness, can be combined into brains which do possesses consciousness.
Answers fall into four categories:
- Materialism – The one fundamental substance in the universe is matter. Matter does not possesses the property of consciousness. However, consciousness is a property which can emerge from certain large and complex configurations of nonconscious matter.
- Substance Dualism – There are two fundamental substances in the universe: 1) nonconscious matter, and 2) some type of conscious substance. The combination of the two produces consciousness in brains.
- Modified Materialism/Panpsychism – The one fundamental substance in the universe is matter. But consciousness is in fact one of the fundamental properties of matter. The amount and organizations of conscious matter in brains produces the consciousness that we experience.
- Idealism – The one fundamental substance in the universe is consciousness. Matter arises from consciousness.
These four positions are all at first glance possible. Each has its supporters and detractors. None has been proven or disproven to the satisfaction of all reasonable people. The answer to your questions depends on which of these views you hold.
Materialism says that a reasonably large and complex nervous system is necessary for something to be consciousness. But materialism cannot draw the line exactly between what does and does not have consciousness. Still, single cell organisms or organisms of any size without a nervous system would most likely not be conscious. All the answers given above are explanations within the materialist framework.
Substance dualism might possibly allow simple organisms like bacteria, or even inanimate objects such as rocks, to be conscious. It is unclear what if any lines might be drawn in this case.
Panpsychism would say that, since all matter possesses consciousness, certainly simple organisms without a nervous system are to some degree conscious.
Idealism would say that the question does not make any sense.
My own view (clearly debatable) is that Materialism is close to being provably false – it seems to me that there exists no way for the property of consciousness to arise from any combination of matter which does not possesses it in the first place.
I am open to one or more of the other three options.