Generally speaking, whether or not a biblical passage can/should be taken literally depends on the context as well as reliable traditions, both of which depend on an acquired level of discernment. An important distinction in this regard is the difference between narrative passages and legal ones (i.e. mitzvoth-commandments). Many symbolic mitzvoth, such as tefillin (e.g. Exodus 13:9), traditionally involve a literal component which cannot be fulfilled with the associated symbolism alone. Nonetheless, other commandments are traditionally (at least according to most authorities) assumed to be "nonliteral", e.g. not placing a stumbling block before the blind (Leviticus 19:14).
Similarly, historical narratives are generally assumed to be literal, even when incorporating events or ideas not prevalent nowadays, such as miracles or unusually long life-spans. However, some narratives if understood in an overly literal fashion, can comprise heresy according to halacha, e.g. corporeality. In addition, many historical passages have been understood allegorically by traditional scholars (see e.g. the Moreh Nevukhim on the first sin; It's also worth noting that traditional scholars [e.g. Rambam, Maharal, Ramchal, Vilna Gaon] reject the literal interpretation of Aggada/Medrash.)