There some documentation about aggregate functions in the manual, for example:
http://www.postgresql.org/docs/7.4/static/sql-createaggregate.html
Here's a simple agg function that should work for you,
assuming your col types are int4.
CREATE AGGREGATE andsum (sfunc = int4and,basetype = int4,stype = int4
);
TJ